home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20081 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.2 KB  |  33 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: offsetof in case labels
  5. Message-ID: <1993Jan22.190518.13167@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1993Jan21.232337.6527@g2syd.genasys.com.au>
  8. Date: Fri, 22 Jan 1993 19:05:18 GMT
  9. Lines: 22
  10.  
  11. roberts@g2syd.genasys.com.au (Robert Swan) writes:
  12.  
  13. >We have a problem on various machines using the offsetof macro from
  14. >stddef.h in case labels.  These machines all reject the expression as
  15. >being non-constant.
  16.  
  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. ANSI C Standard, section 3.6.4.1, "The switch Statement":
  23. "The expression of each case label shall be an integral constant expression."
  24.  
  25. ANSI C Standard, section 4.1.5, "Common Definitions <stddef.h>":
  26. "... offsetof ... expands to an integral constant expression that has
  27. type size_t ..."
  28.  
  29. It seems pretty clear that what you want to do is supposed to be legal.
  30. -- 
  31.  
  32. Steve Clamage, TauMetric Corp, steve@taumet.com
  33.