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: Unions</title>
16
17<meta name="description" content="STABS: Unions">
18<meta name="keywords" content="STABS: Unions">
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="Types.html#Types" rel="up" title="Types">
27<link href="Function-Types.html#Function-Types" rel="next" title="Function Types">
28<link href="Typedefs.html#Typedefs" rel="previous" title="Typedefs">
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="Unions"></a>
63<div class="header">
64<p>
65Next: <a href="Function-Types.html#Function-Types" accesskey="n" rel="next">Function Types</a>, Previous: <a href="Typedefs.html#Typedefs" accesskey="p" rel="previous">Typedefs</a>, Up: <a href="Types.html#Types" accesskey="u" rel="up">Types</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="Unions-1"></a>
69<h3 class="section">5.10 Unions</h3>
70
71<div class="example">
72<pre class="example">union u_tag {
73  int  u_int;
74  float u_float;
75  char* u_char;
76} an_u;
77</pre></div>
78
79<p>This code generates a stab for a union tag and a stab for a union
80variable.  Both use the <code>N_LSYM</code> stab type.  If a union variable is
81scoped locally to the procedure in which it is defined, its stab is
82located immediately preceding the <code>N_LBRAC</code> for the procedure&rsquo;s block
83start.
84</p>
85<p>The stab for the union tag, however, is located preceding the code for
86the procedure in which it is defined.  The stab type is <code>N_LSYM</code>.  This
87would seem to imply that the union type is file scope, like the struct
88type <code>s_tag</code>.  This is not true.  The contents and position of the stab
89for <code>u_type</code> do not convey any information about its procedure local
90scope.
91</p>
92<div class="smallexample">
93<pre class="smallexample"># <span class="roman">128 is N_LSYM</span>
94.stabs &quot;u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;&quot;,
95       128,0,0,0
96</pre></div>
97
98<p>The symbol descriptor &lsquo;<samp>T</samp>&rsquo;, following the &lsquo;<samp>name:</samp>&rsquo; means that
99the stab describes an enumeration, structure, or union tag.  The type
100descriptor &lsquo;<samp>u</samp>&rsquo;, following the &lsquo;<samp>23=</samp>&rsquo; of the type definition,
101narrows it down to a union type definition.  Following the &lsquo;<samp>u</samp>&rsquo; is
102the number of bytes in the union.  After that is a list of union element
103descriptions.  Their format is &lsquo;<samp><var>name</var>:<var>type</var>, <var>bit
104offset into the union</var>, <var>number of bytes for the element</var>;</samp>&rsquo;.
105</p>
106<p>The stab for the union variable is:
107</p>
108<div class="example">
109<pre class="example">.stabs &quot;an_u:23&quot;,128,0,0,-20     # <span class="roman">128 is N_LSYM</span>
110</pre></div>
111
112<p>&lsquo;<samp>-20</samp>&rsquo; specifies where the variable is stored (see <a href="Stack-Variables.html#Stack-Variables">Stack Variables</a>).
113</p>
114
115
116
117</body>
118</html>
119