Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 01 Apr 2005 17:04:35 +0200
From:      des@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=)
To:        standards@freebsd.org
Subject:   offsetof
Message-ID:  <86br8yr118.fsf@xps.des.no>

next in thread | raw e-mail | index | archive | help
I noticed that our definition of offsetof (in <sys/cdefs.h>) is as
follows:

#define __offsetof(type, field) ((size_t)(&((type *)0)->field))

This definition is gratuitously unportable (it assumes that a null
pointer is all-bits-zero).  A better definition would be the
following:

#define __offsetof(type, field) \
        ((size_t)((char *)&((type *)0)->field - (char *)(type *)0))

DES
--=20
Dag-Erling Sm=F8rgrav - des@des.no



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86br8yr118.fsf>