1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- Copyright (C) 1992-2021 Free Software Foundation, Inc. 4Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon, 5and David MacKenzie. 6 7Permission is granted to copy, distribute and/or modify this document 8under the terms of the GNU Free Documentation License, Version 1.3 or 9any later version published by the Free Software Foundation; with no 10Invariant Sections, with no Front-Cover Texts, and with no Back-Cover 11Texts. A copy of the license is included in the section entitled "GNU 12Free Documentation License". --> 13<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 14<head> 15<title>STABS: Simple Classes</title> 16 17<meta name="description" content="STABS: Simple Classes"> 18<meta name="keywords" content="STABS: Simple Classes"> 19<meta name="resource-type" content="document"> 20<meta name="distribution" content="global"> 21<meta name="Generator" content="makeinfo"> 22<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 23<link href="index.html#Top" rel="start" title="Top"> 24<link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index"> 25<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 26<link href="Cplusplus.html#Cplusplus" rel="up" title="Cplusplus"> 27<link href="Class-Instance.html#Class-Instance" rel="next" title="Class Instance"> 28<link href="Basic-Cplusplus-Types.html#Basic-Cplusplus-Types" rel="previous" title="Basic Cplusplus Types"> 29<style type="text/css"> 30<!-- 31a.summary-letter {text-decoration: none} 32blockquote.smallquotation {font-size: smaller} 33div.display {margin-left: 3.2em} 34div.example {margin-left: 3.2em} 35div.indentedblock {margin-left: 3.2em} 36div.lisp {margin-left: 3.2em} 37div.smalldisplay {margin-left: 3.2em} 38div.smallexample {margin-left: 3.2em} 39div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 40div.smalllisp {margin-left: 3.2em} 41kbd {font-style:oblique} 42pre.display {font-family: inherit} 43pre.format {font-family: inherit} 44pre.menu-comment {font-family: serif} 45pre.menu-preformatted {font-family: serif} 46pre.smalldisplay {font-family: inherit; font-size: smaller} 47pre.smallexample {font-size: smaller} 48pre.smallformat {font-family: inherit; font-size: smaller} 49pre.smalllisp {font-size: smaller} 50span.nocodebreak {white-space:nowrap} 51span.nolinebreak {white-space:nowrap} 52span.roman {font-family:serif; font-weight:normal} 53span.sansserif {font-family:sans-serif; font-weight:normal} 54ul.no-bullet {list-style: none} 55--> 56</style> 57 58 59</head> 60 61<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 62<a name="Simple-Classes"></a> 63<div class="header"> 64<p> 65Next: <a href="Class-Instance.html#Class-Instance" accesskey="n" rel="next">Class Instance</a>, Previous: <a href="Basic-Cplusplus-Types.html#Basic-Cplusplus-Types" accesskey="p" rel="previous">Basic Cplusplus Types</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p> 66</div> 67<hr> 68<a name="Simple-Class-Definition"></a> 69<h3 class="section">8.4 Simple Class Definition</h3> 70 71<p>The stabs describing C<tt>++</tt> language features are an extension of the 72stabs describing C. Stabs representing C<tt>++</tt> class types elaborate 73extensively on the stab format used to describe structure types in C. 74Stabs representing class type variables look just like stabs 75representing C language variables. 76</p> 77<p>Consider the following very simple class definition. 78</p> 79<div class="example"> 80<pre class="example">class baseA { 81public: 82 int Adat; 83 int Ameth(int in, char other); 84}; 85</pre></div> 86 87<p>The class <code>baseA</code> is represented by two stabs. The first stab describes 88the class as a structure type. The second stab describes a structure 89tag of the class type. Both stabs are of stab type <code>N_LSYM</code>. Since the 90stab is not located between an <code>N_FUN</code> and an <code>N_LBRAC</code> stab this indicates 91that the class is defined at file scope. If it were, then the <code>N_LSYM</code> 92would signify a local variable. 93</p> 94<p>A stab describing a C<tt>++</tt> class type is similar in format to a stab 95describing a C struct, with each class member shown as a field in the 96structure. The part of the struct format describing fields is 97expanded to include extra information relevant to C<tt>++</tt> class members. 98In addition, if the class has multiple base classes or virtual 99functions the struct format outside of the field parts is also 100augmented. 101</p> 102<p>In this simple example the field part of the C<tt>++</tt> class stab 103representing member data looks just like the field part of a C struct 104stab. The section on protections describes how its format is 105sometimes extended for member data. 106</p> 107<p>The field part of a C<tt>++</tt> class stab representing a member function 108differs substantially from the field part of a C struct stab. It 109still begins with ‘<samp>name:</samp>’ but then goes on to define a new type number 110for the member function, describe its return type, its argument types, 111its protection level, any qualifiers applied to the method definition, 112and whether the method is virtual or not. If the method is virtual 113then the method description goes on to give the vtable index of the 114method, and the type number of the first base class defining the 115method. 116</p> 117<p>When the field name is a method name it is followed by two colons rather 118than one. This is followed by a new type definition for the method. 119This is a number followed by an equal sign and the type of the method. 120Normally this will be a type declared using the ‘<samp>#</samp>’ type 121descriptor; see <a href="Method-Type-Descriptor.html#Method-Type-Descriptor">Method Type Descriptor</a>; static member functions 122are declared using the ‘<samp>f</samp>’ type descriptor instead; see 123<a href="Function-Types.html#Function-Types">Function Types</a>. 124</p> 125<p>The format of an overloaded operator method name differs from that of 126other methods. It is ‘<samp>op$::<var>operator-name</var>.</samp>’ where 127<var>operator-name</var> is the operator name such as ‘<samp>+</samp>’ or ‘<samp>+=</samp>’. 128The name ends with a period, and any characters except the period can 129occur in the <var>operator-name</var> string. 130</p> 131<p>The next part of the method description represents the arguments to the 132method, preceded by a colon and ending with a semi-colon. The types of 133the arguments are expressed in the same way argument types are expressed 134in C<tt>++</tt> name mangling. In this example an <code>int</code> and a <code>char</code> 135map to ‘<samp>ic</samp>’. 136</p> 137<p>This is followed by a number, a letter, and an asterisk or period, 138followed by another semicolon. The number indicates the protections 139that apply to the member function. Here the 2 means public. The 140letter encodes any qualifier applied to the method definition. In 141this case, ‘<samp>A</samp>’ means that it is a normal function definition. The dot 142shows that the method is not virtual. The sections that follow 143elaborate further on these fields and describe the additional 144information present for virtual methods. 145</p> 146 147<div class="display"> 148<pre class="display">.stabs "class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4) 149 field_name(Adat):type(int),bit_offset(0),field_bits(32); 150 151 method_name(Ameth)::type_def(21)=type_desc(method)return_type(int); 152 :arg_types(int char); 153 protection(public)qualifier(normal)virtual(no);;" 154 N_LSYM,NIL,NIL,NIL 155</pre></div> 156 157<div class="smallexample"> 158<pre class="smallexample">.stabs "baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;",128,0,0,0 159 160.stabs "class_name:sym_desc(struct tag)",N_LSYM,NIL,NIL,NIL 161 162.stabs "baseA:T20",128,0,0,0 163</pre></div> 164 165<hr> 166<div class="header"> 167<p> 168Next: <a href="Class-Instance.html#Class-Instance" accesskey="n" rel="next">Class Instance</a>, Previous: <a href="Basic-Cplusplus-Types.html#Basic-Cplusplus-Types" accesskey="p" rel="previous">Basic Cplusplus Types</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p> 169</div> 170 171 172 173</body> 174</html> 175