home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!rpi!usc!srhqla!quest!kdq
- From: kdq@quest.UUCP (Kevin D. Quitt)
- Newsgroups: comp.lang.c
- Subject: Re: offsetof in case labels
- Message-ID: <57kyXB5w165w@quest.UUCP>
- Date: Mon, 25 Jan 93 16:43:27 PST
- References: <1993Jan21.232337.6527@g2syd.genasys.com.au>
- Reply-To: srhqla!quest!kdq
- Organization: Job quest (805) 251-8210, So Cal: (800) 400-8210
- Lines: 39
-
- roberts@g2syd.genasys.com.au (Robert Swan) writes:
-
- > We have a problem on various machines using the offsetof macro from
- > stddef.h in case labels. These machines all reject the expression as
- > being non-constant.
- >
- > A representative of one of the machine vendors (IBM), has glibly stated
- > that the compiler is doing the right thing by rejecting it. He has
- > quoted the ANSI standard arguing (in fairly obscure terms) that the
- > compiler is free to treat various pointer expressions as non constant.
- ...
- > Should offsetof be usable in case labels?
-
- Yes. From ANSI (not ISO) 4.1.5 (_word_ is an italic word):
-
- Common Definitions <stddef.h>
-
- The following types and macros are defined in the standard header
- <stddef.h>...
- The macros are NULL which expands to an implementation-defined null
- pointer constant, and offsetof( _type_, _member-expression_ ) which
- expands to an integral constant expression that has size size_t, the
- value of which is the offset in bytes, to the structure member
- (designated by _member-expression_), from the beginning of its
- structure (designated by _type_). The _member-designator_ shall be
- such that given
-
- static _type_ t;
-
- then the expression &(t._member-expression_) evaluates to a address
- constant. (If the specified member is a bit-field, the behaviour is
- undefined).
-
-
- So, unless you're using a bit-field member, it's gotta work.
-
-
- _
- Kevin D. Quitt 96.37% of all statistics are made up. srhqla!quest!kdq
-