🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1771

offsetof (was [m]allocation question)

#1771
From: Peter Moore
Date: Mon, 01 Oct 1990 02:23
20 lines
1151 bytes
The validity of sizeof((type *)->field)) is especially interesting given
the sample (though carefully described as unportable) definitions of offsetof
in the Rationale (4.1.5: pg 75):

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

This isn't going to work if sizeof((type *)->field) doesn't work.

By the way, the above definition of offsetof always seemed like a bad one,
since it makes the unnecessary assumption that the null pointer has a 0
bit-pattern.  Now practically, that is probably true for almost all compilers,
if only because there is so much code that implicitly depends on it.  But
wouldn't a more politically correct example be:

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


	Peter Moore
	peter@objy.com
Technical Details
Message-ID: <1990Sep30.192325@objy.objy.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!decwrl!sgi!llustig!objy!objy!peter

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!decwrl!sgi!llustig!objy!objy!peter
From: peter@objy.objy.com (Peter Moore)
Newsgroups: comp.std.c
Subject: offsetof (was [m]allocation question)
Message-ID: <1990Sep30.192325@objy.objy.com>
Date: 1 Oct 90 02:23:25 GMT
Sender: news@objy.com
Reply-To: peter@objy.com
Organization: Objectivity Inc.
Lines: 20