Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/share/man/man3 Add example.



details:   https://anonhg.NetBSD.org/src/rev/ae45ea6365fe
branches:  trunk
changeset: 763722:ae45ea6365fe
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Fri Apr 01 05:24:37 2011 +0000

description:
Add example.

diffstat:

 share/man/man3/offsetof.3 |  24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diffs (45 lines):

diff -r 0beee6b82af1 -r ae45ea6365fe share/man/man3/offsetof.3
--- a/share/man/man3/offsetof.3 Fri Apr 01 00:47:11 2011 +0000
+++ b/share/man/man3/offsetof.3 Fri Apr 01 05:24:37 2011 +0000
@@ -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 ,



Home | Main Index | Thread Index | Old Index