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: Virtual Base Classes</title>
16
17<meta name="description" content="STABS: Virtual Base Classes">
18<meta name="keywords" content="STABS: Virtual Base 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="Static-Members.html#Static-Members" rel="next" title="Static Members">
28<link href="Inheritance.html#Inheritance" rel="previous" title="Inheritance">
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="Virtual-Base-Classes"></a>
63<div class="header">
64<p>
65Next: <a href="Static-Members.html#Static-Members" accesskey="n" rel="next">Static Members</a>, Previous: <a href="Inheritance.html#Inheritance" accesskey="p" rel="previous">Inheritance</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> &nbsp; [<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="Virtual-Base-Classes-1"></a>
69<h3 class="section">8.13 Virtual Base Classes</h3>
70
71<p>A derived class object consists of a concatenation in memory of the data
72areas defined by each base class, starting with the leftmost and ending
73with the rightmost in the list of base classes.  The exception to this
74rule is for virtual inheritance.  In the example above, class <code>D</code>
75inherits virtually from base class <code>B</code>.  This means that an
76instance of a <code>D</code> object will not contain its own <code>B</code> part but
77merely a pointer to a <code>B</code> part, known as a virtual base pointer.
78</p>
79<p>In a derived class stab, the base offset part of the derivation
80information, described above, shows how the base class parts are
81ordered.  The base offset for a virtual base class is always given as 0.
82Notice that the base offset for <code>B</code> is given as 0 even though
83<code>B</code> is not the first base class.  The first base class <code>A</code>
84starts at offset 0.
85</p>
86<p>The field information part of the stab for class <code>D</code> describes the field
87which is the pointer to the virtual base class <code>B</code>. The vbase pointer
88name is &lsquo;<samp>$vb</samp>&rsquo; followed by a type reference to the virtual base class.
89Since the type id for <code>B</code> in this example is 25, the vbase pointer name
90is &lsquo;<samp>$vb25</samp>&rsquo;.
91</p>
92<div class="smallexample">
93<pre class="smallexample">.stabs &quot;D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:1,
94       160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt::32:i;
95       2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;28;;D_virt:
96       :32:i;2A*-2147483646;31;;;~%20;&quot;,128,0,0,0
97</pre></div>
98
99<p>Following the name and a semicolon is a type reference describing the
100type of the virtual base class pointer, in this case 24.  Type 24 was
101defined earlier as the type of the <code>B</code> class <code>this</code> pointer.  The
102<code>this</code> pointer for a class is a pointer to the class type.
103</p>
104<div class="example">
105<pre class="example">.stabs &quot;this:P24=*25=xsB:&quot;,64,0,0,8
106</pre></div>
107
108<p>Finally the field offset part of the vbase pointer field description
109shows that the vbase pointer is the first field in the <code>D</code> object,
110before any data fields defined by the class.  The layout of a <code>D</code>
111class object is a follows, <code>Adat</code> at 0, the vtable pointer for
112<code>A</code> at 32, <code>Cdat</code> at 64, the vtable pointer for C at 96, the
113virtual base pointer for <code>B</code> at 128, and <code>Ddat</code> at 160.
114</p>
115
116<hr>
117<div class="header">
118<p>
119Next: <a href="Static-Members.html#Static-Members" accesskey="n" rel="next">Static Members</a>, Previous: <a href="Inheritance.html#Inheritance" accesskey="p" rel="previous">Inheritance</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> &nbsp; [<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>
120</div>
121
122
123
124</body>
125</html>
126