Add example.

This commit is contained in:
jruoho 2011-04-01 05:24:37 +00:00
parent 5940ea9676
commit 182bf29856

View File

@ -1,4 +1,4 @@
.\" $NetBSD: offsetof.3,v 1.3 2010/12/19 08:10:09 jruoho Exp $
.\" $NetBSD: offsetof.3,v 1.4 2011/04/01 05:24:37 jruoho Exp $
.\"
.\" $OpenBSD: offsetof.3,v 1.2 2010/02/18 18:30:19 jmc Exp $
.\"
@ -17,7 +17,7 @@
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\"
.Dd December 19, 2010
.Dd April 1, 2011
.Dt OFFSETOF 3
.Os
.Sh NAME
@ -41,6 +41,26 @@ from the start of the structure
A compiler error will result if
.Ar member
is not aligned to a byte boundary (i.e. it is a bit-field).
.Sh EXAMPLES
Regardless of the architecture and the
.Tn ABI ,
the following example prints the value zero for the variable
.Va x .
.Bd -literal -offset indent
struct example {
double x;
int y;
char z;
};
size_t x, y, z;
x = offsetof(struct example, x);
y = offsetof(struct example, y);
z = offsetof(struct example, z);
(void)printf(\*[q]%zu %zu %zu\en\*[q], x, y, z);
.Ed
.Sh SEE ALSO
.Xr __alignof__ 3 ,
.Xr stddef 3 ,