
12 Cal.2d 579 (1939)
In the Matter of the Application of WESTY PETRAEUS, Jr., for a Writ of Habeas Corpus.
Crim. No. 4199. 
Supreme Court of California. In Bank.  
January 17, 1939.
 W. I. Gilbert and James B. Fredericks for Petitioner.
 Buron Fitts, District Attorney (Los Angeles County), and A. H. Van Cott, Deputy District Attorney, for Respondent. *580
 SHENK, J.
 The question for determination in this proceeding is whether one who has given self-incriminating testimony as a witness in the defense of another on trial for the crime of gaming, may invoke the immunity provided by section 334 of the Penal Code.
 Margaret Petraeus and Westy Petraeus, Jr., were charged by separate informations with violations of section 337a, subdivision 2, of the Penal Code. Margaret Petraeus was tried first. On her trial she called Westy Petraeus, Jr., as her witness. Without claiming the constitutional privilege against self-incrimination, he gave testimony on behalf of Margaret Petraeus which implicated him in the commission of the crime with which he was charged. The jury in the trial of Margaret Petraeus failed to agree upon a verdict. Upon his own trial, Westy Petraeus, Jr., claimed immunity by virtue of the provisions of section 334 of the Penal Code, but this was denied. He was convicted and thereupon commenced the present proceeding to obtain his release from custody, basing his petition for the writ of habeas corpus upon the same claim,
 Section 334 of the Penal Code reads: "No person, otherwise competent as a witness, is disqualified from testifying as such concerning the offense of gaming, on the ground that such testimony may criminate himself; but no prosecution can afterwards be had against him for any offense concerning which he testified."
 The petitioner relies on the literal language of this section and on a statement in the case of In re Williams, 127 Cal.App. 424 [16 PaCal.2d 172], referred to in In re Critchlow, 11 Cal.2d 751 [81 PaCal.2d 966], in support of his claim.
 In the opinion in the Williams case it was said at page 431: "What the statute means is that a witness called to testify to facts concerning or relating to the offense of gaming can safely testify for the reason that he is forever free from the possibility of punishment for any crime in the proof of which such testimony would be material. Such a construction is literally what the statute says, and it preserves the whole meaning and intention thereof. Such construction brings the statute within the rule that it must be coextensive with the Constitution. ... Any witness who testifies to facts concerning or relating to prohibited gaming is immune from punishment *581 for any offense in the proof of which such facts would be relevant and material."
 In that case the petitioner was called as a witness for the People in a preliminary hearing of gaming charges against others. He refused to answer certain questions asked on behalf of the People on the ground that his answers would tend to incriminate him. He was adjudged in contempt and committed to jail. On his application for a writ of habeas corpus the following propositions were decided: (1) That section 334 of the Penal Code comprehended all offenses of gaming or gambling, including those defined in section 337a of the same code; (2) That conspiracy to violate any of such sections was also an offense concerning gambling and within the comprehension of the immunity section; (3) That any witness referred to by section 334 of the Penal Code must be afforded an immunity coextensive with the constitutional privilege against being compelled to give self-incriminating testimony; (4) that the section afforded such immunity and therefore that the petitioner in that case was under compulsion to give the incriminatory answers as to relevant matters because he was fully protected against future punishment on account of any offense as to which he might thus testify.
 In the Critchlow case the witness was subpoenaed to appear and answer before the grand jury. She claimed the constitutional privilege against self-incrimination and resisted compulsion to testify as to certain bribery activities in connection with violations of the gaming law. The language quoted from the Williams case was referred to as stating the correct rule of law in considering the question of the coextensiveness of the immunity given by section 334 of the Penal Code with the constitutional privilege.
 [1] We are aware of no case or authority, and the petitioner has cited none, which holds that one who gives self-incriminating testimony on behalf of the defense in a criminal proceeding or investigation, may thereafter claim the right, under any immunity statute, to go unpunished for the crime so confessed. The protection of the witness in such circumstances is not the immunity statute, but the constitutional provision which guards him from the compulsory revelation of self-incriminating evidence.
 The history of the origin of the constitutional privilege, and the development of the custom of granting immunity by *582 prosecuting authorities in aid of the administration of justice, was referred to without extended discussion in the Critchlow case. It was there pointed out that one curtailment of the right to invoke the constitutional privilege occurs during an investigation by a prosecuting or indicting body, in certain classes of cases specified by statutory law, wherein immunity is granted in exchange for information against other offenders. [2] It must be obvious that it was not the intention either in the Critchlow case or in the Williams case to intimate that one who testified for the defense in a criminal proceeding could invoke the immunity provided by section 334 of the Penal Code. Such testimony is voluntary and is not under the compulsion which a reference to the history and development of such system or custom discloses as a necessary element within the meaning of the immunity granting system prescribed by the code sections. Such compulsion is present only when a witness is called by the prosecution, as to whom alone section 334 applies. That this is so is also indicated by the immediately preceding section of the Penal Code, namely, section 333, which provides: "Every person duly summoned as a witness for the prosecution, on any proceedings had under this chapter, who neglects or refuses to attend, as required, is guilty of a misdemeanor." Reading these sections together leads directly to the conclusion that the legislative intent was that witnesses for the prosecution were referred to by the language of section 334. There is no justification in law for reading the language of the latter section apart from other sections bearing upon the same subject-matter and which are in pari materia, where to do so would lead to the absurd conclusion that a witness may volunteer testimony on behalf of the defense, thereby incriminate himself, clear the accused and both escape punishment.
 [3] The petitioner contends that his testimony was "compulsory" because the defendant on whose behalf he testified was entitled to prove her innocence by showing that another was guilty. But it would not follow that one who is willing to confess a crime to exonerate another should necessarily go unpunished. The argument loses sight of the quid pro quo in the matter of granting immunity by the state, namely, information leading to the arrest and conviction of offenders. The petitioner would have the court extend the immunity beyond *583 its clear ends and limits, that is, to situations wherein the state is assumed to have bargained to give all without any return. This was not the legislative purpose.
 [4] Additional support for the foregoing conclusion may be found in the rule that a statute must be construed with reference to the object to be accomplished (People v. Dana, 22 Cal. 11, 20; Bannerman v. Boyle, 160 Cal. 197, 200 [116 P. 732]; Johnston v. Baker, 167 Cal. 260, 264 [139 P. 86]; Gise v. Myers, 22 Cal.App. 127 [133 P. 500]; Golden & Co. v. Justice's Court, 23 Cal.App. 778, 794 [140 P. 49]; Spier v. Peck, 36 Cal.App. 4, 6 [171 P. 115]), and the rule that code sections relating to a particular subject are in pari materia and should be read and considered together (23 Cal.Jur. 791; People v. Parvin, 74 Cal. 549, 555 [16 P. 490]; People v. Upton, 67 Cal.App. 445, 450 [228 P. 50]).
 The writ is discharged and the prisoner is remanded to custody.
 Curtis, J., Langdon, J., Waste, C.J., and Seawell, J., concurred.
