Files
oldlinux-files/Ref-docs/c_lib_guide/2.11.html
2024-02-19 00:21:47 -05:00

109 lines
2.6 KiB
HTML

<html>
<head>
<title>
C Guide--2.11 stddef.h
</title>
<!-- Changed by: eric huss, 12-Mar-1997 -->
</head>
<body text="#000000" bgcolor="#FFFFFF">
<center>
<table border=0 width=100%>
<tr>
<td align=left width=20% valign=top>
<a href="2.10.html">
<img src="left.gif" border=0>
Previous Section<br>
2.10 stdarg.h</a></td>
<td align=center width=60% valign=top>
| <a href="index.html">Table of Contents</a> |
<a href="index2.html">Index</a> |</td>
<td align=right width=20% valign=top>
<a href="2.12.html">
Next Section
<img src="right.gif" border=0><br>
2.12 stdio.h</a></td>
</tr>
</table>
</center>
<hr>
<h1> 2.11 stddef.h</h1>
<p>
The stddef header defines several standard definitions. Many of these definitions also
appear in other headers.
<p>
Macros:
<blockquote><code><b>
NULL<br>
offsetof();<br>
</b></code></blockquote>
Variables:
<blockquote><code><b>
typedef ptrdiff_t<br>
typedef size_t<br>
typedef wchar_t<br>
</b></code></blockquote>
<a name="variables"></a>
<h2>2.11.1 Variables and Definitions</h2>
<p>
<code><b>ptrdiff_t</b></code> is the result of subtracting two pointers.<br>
<code><b>size_t</b></code> is the unsigned integer result of the sizeof keyword.<br>
<code><b>wchar_t</b></code> is an integer type of the size of a wide character constant.<br>
<p>
<code><b>NULL</b></code> is the value of a null pointer constant.
<p>
<code><b>offsetof(</b></code><i>type</i><code><b>,</b></code><i> member-designator</i><code><b>)</b></code>
<p>
This results in a constant integer of type <code><b>size_t</b></code> which is the offset in bytes of a structure
member from the beginning of the structure. The member is given by <i>member-designator</i>, and
the name of the structure is given in <i>type</i>.
<p>
Example:
<blockquote><code><b><pre>
#include&lt;stddef.h&gt;
#include&lt;stdio.h&gt;
int main(void)
{
struct user{
char name[50];
char alias[50];
int level;
};
printf("level is the %d byte in the user structure.\n"),
offsetof(struct user,level));
}
</pre></b></code></blockquote>
The output should be:<br>
<pre>
level is the 100 byte in the user structure.
</pre>
<hr>
<center>
<table border=0 width=100%>
<tr>
<td align=left width=20% valign=top>
<a href="2.10.html">
<img src="left.gif" border=0>
Previous Section<br>
2.10 stdarg.h</a></td>
<td align=center width=60% valign=top>
| <a href="index.html">Table of Contents</a> |
<a href="index2.html">Index</a> |</td>
<td align=right width=20% valign=top>
<a href="2.12.html">
Next Section
<img src="right.gif" border=0><br>
2.12 stdio.h</a></td>
</tr>
</table>
</center>
</body>
</html>