offsetof

Garrett Wollman wollman at khavrinen.lcs.mit.edu
Fri Apr 1 07:28:05 PST 2005


<<On Fri, 01 Apr 2005 17:04:35 +0200, des at des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) said:

> 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).

offsetof() is not supposed to be portable; that's why C requires that
the implementation define it.  In any case, for any architecture that
FreeBSD runs on, the null pointer will be all-bits-zero.

-GAWollman



More information about the freebsd-standards mailing list