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

  1. Xref: sparky comp.lang.c:20146 comp.std.c:3406
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sdd.hp.com!zaphod.mps.ohio-state.edu!howland.reston.ans.net!bogus.sura.net!udel!gatech!hubcap!ncrcae!ncrhub2!ncrgw2!psinntp!heimdall!thor!scjones
  3. From: scjones@thor.sdrc.com (Larry Jones)
  4. Newsgroups: comp.lang.c,comp.std.c
  5. Subject: Re: offsetof in case labels
  6. Message-ID: <542@heimdall.sdrc.com>
  7. Date: 24 Jan 93 18:27:54 GMT
  8. References: <1993Jan21.232337.6527@g2syd.genasys.com.au>
  9. Sender: news@heimdall.sdrc.com
  10. Followup-To: comp.std.c
  11. Lines: 56
  12.  
  13. In article <1993Jan21.232337.6527@g2syd.genasys.com.au>, roberts@g2syd.genasys.com.au (Robert Swan) writes:
  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.  
  18. Those compilers are not ANSI/ISO conforming.  The ANSI/ISO C Standard
  19. clearly requires offsetof to expand to an integral constant expression
  20. which, as you noted, is exactly what is required for a case label. 
  21. (Since this is a standards question, I've also posted this to comp.std.c
  22. and redirected follow-ups there.)
  23.  
  24. > A representative of one of the machine vendors (IBM), has glibly stated
  25. > that the compiler is doing the right thing by rejecting it.
  26.  
  27. He is mistaken.  By an amazing coincidence, X3J11 has received a request
  28. for interpretation from someone at IBM on exactly this point.  This RFI
  29. points out that it is not possible to write an offsetof macro that
  30. expands to strictly conforming code (which is precisely why the macro
  31. exists -- if you could do it yourself, the macro would be redundant) and
  32. arguing that this makes any program that uses offsetof not strictly
  33. conforming and thus an implementation is free to reject it.  This is, of
  34. course, nonsense -- an otherwise strictly conforming program that uses
  35. offsetof in a strictly conforming fashion is still strictly conforming
  36. reguardless of the expansion of the macro.  The RFI, suspecting this to
  37. be the committee's response, goes on to point out that this *requires*
  38. an implementation to implement an extension of some sort in order to
  39. implement offsetof and argues that this is inappropriate.  While this is
  40. the most common method of implementing offsetof (generally by extending
  41. the implementation's definition of constant expression, which the
  42. standard allows, or by adding a new keyword), it is not, strictly
  43. speaking, necessary.  All that is required is an omniscient preprocessor
  44. that can expand offsetof to the correct integer constant -- not a
  45. difficult task if the preprocessor is an integral part of the compiler
  46. with access to the symbol table.
  47.  
  48. (These are my recollections of the RFI and the committee's discussions
  49. -- there is no guarantee that they match anyone else's recollections or
  50. the actual facts.  Those who care should obtain the collected Requests
  51. for Interpretation and Responses which ANSI should be publishing as a
  52. Technical Information Bulletin real soon now.)
  53.  
  54. > However, I'm pretty much at sea with the ANSI standard - we don't have a
  55. > copy, and the excerpts I have seen of it suggest that it is written in
  56. > sufficiently obscure legalese to cloud the superficial interpretation I
  57. > might put on it.
  58.  
  59. On the contrary, it's actually quite readable for a language standard; a
  60. bit more difficult than K&R Appendix A, perhaps, but not significantly
  61. so.
  62. ----
  63. Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
  64. larry.jones@sdrc.com
  65. Pitiful.  Just pitiful. -- Calvin
  66.  
  67.  
  68.  
  69.