Module Name: src
Committed By: jruoho
Date: Fri Apr 1 05:24:37 UTC 2011
Modified Files:
src/share/man/man3: offsetof.3
Log Message:
Add example.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/share/man/man3/offsetof.3
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/share/man/man3/offsetof.3
diff -u src/share/man/man3/offsetof.3:1.3 src/share/man/man3/offsetof.3:1.4
--- src/share/man/man3/offsetof.3:1.3 Sun Dec 19 08:10:09 2010
+++ src/share/man/man3/offsetof.3 Fri Apr 1 05:24:37 2011
@@ -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 @@
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 ,