Justin,
> Included is a manpage documenting the offsetof() macro; please
> consider including it.
Excellent idea! Thanks for the page. It will go in 2.34.
> .\" Copyright (C) 2006 Justin Pryzby <[EMAIL PROTECTED]>
> .\"
> .\" Permission is hereby granted, free of charge, to any person obtaining
> .\" a copy of this software and associated documentation files (the
> .\" "Software"), to deal in the Software without restriction, including
> .\" without limitation the rights to use, copy, modify, merge, publish,
> .\" distribute, sublicense, and/or sell copies of the Software, and to
> .\" permit persons to whom the Software is furnished to do so, subject to
> .\" the following conditions:
> .\"
> .\" The above copyright notice and this permission notice shall be
> .\" included in all copies or substantial portions of the Software.
> .\"
> .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> .\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> .\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
> .\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> .\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> .\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> .\"
> .\" References:
> .\" /usr/lib/gcc/i486-linux-gnu/4.1.1/include/stddef.h
> .\" glibc-doc
> .TH ERROR 3 "2006-05-23" GNU
> .SH NAME
> offsetof \- offset of a structure member
> .SH SYNOPSIS
> \fB#include <stddef.h>
>
> \fBsize_t offsetof(\fItype\fP, \fPmember\fP);
> .SH DESCRIPTION
> \fBoffsetof\fP() is a macro provided to compute the offset of a given
> element within a structure. The ordering within memory of a C
> structure is undefined, as is its size; compilers are allowed to
> reorder and pad structures. An element's offset is not necessarily
> given by the sum of the sizes of the previous elements' sizes; use
> \fBoffsetof\fP() instead.
> .SH "RETURN VALUE"
> \fBoffsetof\fP() returns the offset of the given element within the
> given datatype, in units of bytes.
> .SH EXAMPLE PROGRAM
> .nf
> #include <stddef.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
> struct a {
I prefer 4-space indents for code. I'll change that.
> int i;
> char c;
> double d;
> };
>
> /* Output is compiler-dependant */
Please put your pages through a spell checker. (A fault that
I'm also sometimes guilty of...)
> printf("%d\n", offsetof(struct a, c));
> exit(EXIT_SUCCESS);
> }
> .fi
> .SH NOTES
> \fBoffsetof\fP can be implemented as:
> .sp
> .nf
> \fB#define offsetof(\fItype\fP, \fPmember\fP) \\
> \fB&((type *)0)->\fImember\fP - (char *)((\fPtype\fP *)0)
> .fi
I'm inclined to leave the above out (it could vary on some systems).
But anyway, why do you write the above when glibc says:
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
?
> .SH "CONFORMING TO"
> \fBoffsetof\fP() is a POSIX requirement.
Just: "POSIX.1-2001." will do.
> .\" .SH SEE ALSO
Yes, I don't think of anything to SEE either.
I will forward my revision of the page later.
Cheers,
Michael
--
Michael Kerrisk
maintainer of Linux man pages Sections 2, 3, 4, 5, and 7
Want to help with man page maintenance?
Grab the latest tarball at
ftp://ftp.win.tue.nl/pub/linux-local/manpages/,
read the HOWTOHELP file and grep the source
files for 'FIXME'.
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]