89 lines
4.2 KiB
HTML
89 lines
4.2 KiB
HTML
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>Unions - STABS</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html">
|
||
|
<meta name="description" content="STABS">
|
||
|
<meta name="generator" content="makeinfo 4.13">
|
||
|
<link title="Top" rel="start" href="index.html#Top">
|
||
|
<link rel="up" href="Types.html#Types" title="Types">
|
||
|
<link rel="prev" href="Typedefs.html#Typedefs" title="Typedefs">
|
||
|
<link rel="next" href="Function-Types.html#Function-Types" title="Function Types">
|
||
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
||
|
<!--
|
||
|
Copyright (C) 1992-2019 Free Software Foundation, Inc.
|
||
|
Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon,
|
||
|
and David MacKenzie.
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document
|
||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||
|
any later version published by the Free Software Foundation; with no
|
||
|
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
|
||
|
Texts. A copy of the license is included in the section entitled ``GNU
|
||
|
Free Documentation License''.-->
|
||
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
||
|
<style type="text/css"><!--
|
||
|
pre.display { font-family:inherit }
|
||
|
pre.format { font-family:inherit }
|
||
|
pre.smalldisplay { font-family:inherit; font-size:smaller }
|
||
|
pre.smallformat { font-family:inherit; font-size:smaller }
|
||
|
pre.smallexample { font-size:smaller }
|
||
|
pre.smalllisp { font-size:smaller }
|
||
|
span.sc { font-variant:small-caps }
|
||
|
span.roman { font-family:serif; font-weight:normal; }
|
||
|
span.sansserif { font-family:sans-serif; font-weight:normal; }
|
||
|
--></style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="node">
|
||
|
<a name="Unions"></a>
|
||
|
<p>
|
||
|
Next: <a rel="next" accesskey="n" href="Function-Types.html#Function-Types">Function Types</a>,
|
||
|
Previous: <a rel="previous" accesskey="p" href="Typedefs.html#Typedefs">Typedefs</a>,
|
||
|
Up: <a rel="up" accesskey="u" href="Types.html#Types">Types</a>
|
||
|
<hr>
|
||
|
</div>
|
||
|
|
||
|
<h3 class="section">5.10 Unions</h3>
|
||
|
|
||
|
<pre class="example"> union u_tag {
|
||
|
int u_int;
|
||
|
float u_float;
|
||
|
char* u_char;
|
||
|
} an_u;
|
||
|
</pre>
|
||
|
<p>This code generates a stab for a union tag and a stab for a union
|
||
|
variable. Both use the <code>N_LSYM</code> stab type. If a union variable is
|
||
|
scoped locally to the procedure in which it is defined, its stab is
|
||
|
located immediately preceding the <code>N_LBRAC</code> for the procedure's block
|
||
|
start.
|
||
|
|
||
|
<p>The stab for the union tag, however, is located preceding the code for
|
||
|
the procedure in which it is defined. The stab type is <code>N_LSYM</code>. This
|
||
|
would seem to imply that the union type is file scope, like the struct
|
||
|
type <code>s_tag</code>. This is not true. The contents and position of the stab
|
||
|
for <code>u_type</code> do not convey any information about its procedure local
|
||
|
scope.
|
||
|
|
||
|
<!-- FIXME: phony line break. Can probably be fixed by using an example -->
|
||
|
<!-- with fewer fields. -->
|
||
|
<pre class="smallexample"> # <span class="roman">128 is N_LSYM</span>
|
||
|
.stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
|
||
|
128,0,0,0
|
||
|
</pre>
|
||
|
<p>The symbol descriptor ‘<samp><span class="samp">T</span></samp>’, following the ‘<samp><span class="samp">name:</span></samp>’ means that
|
||
|
the stab describes an enumeration, structure, or union tag. The type
|
||
|
descriptor ‘<samp><span class="samp">u</span></samp>’, following the ‘<samp><span class="samp">23=</span></samp>’ of the type definition,
|
||
|
narrows it down to a union type definition. Following the ‘<samp><span class="samp">u</span></samp>’ is
|
||
|
the number of bytes in the union. After that is a list of union element
|
||
|
descriptions. Their format is ‘<samp><var>name</var><span class="samp">:</span><var>type</var><span class="samp">, </span><var>bit
|
||
|
offset into the union</var><span class="samp">, </span><var>number of bytes for the element</var><span class="samp">;</span></samp>’.
|
||
|
|
||
|
<p>The stab for the union variable is:
|
||
|
|
||
|
<pre class="example"> .stabs "an_u:23",128,0,0,-20 # <span class="roman">128 is N_LSYM</span>
|
||
|
</pre>
|
||
|
<p>‘<samp><span class="samp">-20</span></samp>’ specifies where the variable is stored (see <a href="Stack-Variables.html#Stack-Variables">Stack Variables</a>).
|
||
|
|
||
|
</body></html>
|
||
|
|