🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5313

Re: The offsetof macro

#5313
From: T. William Wells
Date: Sun, 28 Aug 1988 23:20
29 lines
1604 bytes
In article <16490006@hpcllca.HP.COM> walter@hpcllca.HP.COM (Walter Murray) writes:
: I think this may have been discussed a few months ago in comp.lang.c.
: If so, would someone please mail or post the consensus that was
: reached?
:
: The offsetof macro is supposed to expand to an integral constant
: expression.  There are strict rules about the operands and casts
: that can be used in an integral constant expression, so, for
: example, an expression containing "(type *)0" wouldn't be legal.
: Using such an illegal expression in a place where an integral
: constant expression is required, such as a case label expression,
: would violate a constraint and would seemingly require a diagnostic
: to be produced.
:
: So what is a valid way to define offsetof?

There isn't any portable way that I can think of.  I wouldn't be
surprised if that is why it is defined in a header file where the
compiler is free to define it any way it wants.  For example, it
could be defined as:

#define offsetof(type,mem) __offsetof_kludge(type,mem)

and, could then treat __offsetof_kludge somewhat as it might
treat sizeof.

---
Bill
novavax!proxftl!bill
Technical Details
Message-ID: <643@proxftl.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!alberta!ubc-cs!uw-beaver!cornell!mailrus!uflorida!novavax!proxftl!bill
References: <16490006@hpcllca.HP.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!alberta!ubc-cs!uw-beaver!cornell!mailrus!uflorida!novavax!proxftl!bill
From: bill@proxftl.UUCP (T. William Wells)
Newsgroups: comp.std.c
Subject: Re: The offsetof macro
Message-ID: <643@proxftl.UUCP>
Date: 28 Aug 88 23:20:21 GMT
References: <16490006@hpcllca.HP.COM>
Reply-To: bill@proxftl.UUCP (T. William Wells)
Organization: Proximity Technology, Ft. Lauderdale
Lines: 29