home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20318 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.8 KB

  1. Path: sparky!uunet!think.com!rpi!usc!srhqla!quest!kdq
  2. From: kdq@quest.UUCP (Kevin D. Quitt)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: offsetof in case labels
  5. Message-ID: <57kyXB5w165w@quest.UUCP>
  6. Date: Mon, 25 Jan 93 16:43:27 PST
  7. References: <1993Jan21.232337.6527@g2syd.genasys.com.au>
  8. Reply-To: srhqla!quest!kdq
  9. Organization: Job quest  (805) 251-8210,  So Cal: (800) 400-8210
  10. Lines: 39
  11.  
  12. roberts@g2syd.genasys.com.au (Robert Swan) writes:
  13.  
  14. > We have a problem on various machines using the offsetof macro from
  15. > stddef.h in case labels.  These machines all reject the expression as
  16. > being non-constant.
  17. > A representative of one of the machine vendors (IBM), has glibly stated
  18. > that the compiler is doing the right thing by rejecting it.  He has
  19. > quoted the ANSI standard arguing (in fairly obscure terms) that the
  20. > compiler is free to treat various pointer expressions as non constant.
  21. ...
  22. > Should offsetof be usable in case labels?
  23.  
  24.     Yes.  From ANSI (not ISO) 4.1.5 (_word_ is an italic word):
  25.  
  26. Common Definitions <stddef.h>
  27.  
  28. The following types and macros are defined in the standard header
  29. <stddef.h>...
  30. The macros are NULL which expands to an implementation-defined null
  31. pointer constant, and offsetof( _type_, _member-expression_ ) which
  32. expands to an integral constant expression that has size size_t, the
  33. value of which is the offset in bytes, to the structure member
  34. (designated by _member-expression_), from the beginning of its
  35. structure (designated by _type_).  The _member-designator_ shall be
  36. such that given
  37.  
  38. static _type_ t;
  39.  
  40. then the expression &(t._member-expression_) evaluates to a address
  41. constant.  (If the specified member is a bit-field, the behaviour is
  42. undefined).
  43.  
  44.  
  45.     So, unless you're using a bit-field member, it's gotta work.
  46.  
  47.  
  48.  _
  49. Kevin D. Quitt      96.37% of all statistics are made up.     srhqla!quest!kdq
  50.