home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:20146 comp.std.c:3406
- 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
- From: scjones@thor.sdrc.com (Larry Jones)
- Newsgroups: comp.lang.c,comp.std.c
- Subject: Re: offsetof in case labels
- Message-ID: <542@heimdall.sdrc.com>
- Date: 24 Jan 93 18:27:54 GMT
- References: <1993Jan21.232337.6527@g2syd.genasys.com.au>
- Sender: news@heimdall.sdrc.com
- Followup-To: comp.std.c
- Lines: 56
-
- In article <1993Jan21.232337.6527@g2syd.genasys.com.au>, 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.
-
- Those compilers are not ANSI/ISO conforming. The ANSI/ISO C Standard
- clearly requires offsetof to expand to an integral constant expression
- which, as you noted, is exactly what is required for a case label.
- (Since this is a standards question, I've also posted this to comp.std.c
- and redirected follow-ups there.)
-
- > A representative of one of the machine vendors (IBM), has glibly stated
- > that the compiler is doing the right thing by rejecting it.
-
- He is mistaken. By an amazing coincidence, X3J11 has received a request
- for interpretation from someone at IBM on exactly this point. This RFI
- points out that it is not possible to write an offsetof macro that
- expands to strictly conforming code (which is precisely why the macro
- exists -- if you could do it yourself, the macro would be redundant) and
- arguing that this makes any program that uses offsetof not strictly
- conforming and thus an implementation is free to reject it. This is, of
- course, nonsense -- an otherwise strictly conforming program that uses
- offsetof in a strictly conforming fashion is still strictly conforming
- reguardless of the expansion of the macro. The RFI, suspecting this to
- be the committee's response, goes on to point out that this *requires*
- an implementation to implement an extension of some sort in order to
- implement offsetof and argues that this is inappropriate. While this is
- the most common method of implementing offsetof (generally by extending
- the implementation's definition of constant expression, which the
- standard allows, or by adding a new keyword), it is not, strictly
- speaking, necessary. All that is required is an omniscient preprocessor
- that can expand offsetof to the correct integer constant -- not a
- difficult task if the preprocessor is an integral part of the compiler
- with access to the symbol table.
-
- (These are my recollections of the RFI and the committee's discussions
- -- there is no guarantee that they match anyone else's recollections or
- the actual facts. Those who care should obtain the collected Requests
- for Interpretation and Responses which ANSI should be publishing as a
- Technical Information Bulletin real soon now.)
-
- > However, I'm pretty much at sea with the ANSI standard - we don't have a
- > copy, and the excerpts I have seen of it suggest that it is written in
- > sufficiently obscure legalese to cloud the superficial interpretation I
- > might put on it.
-
- On the contrary, it's actually quite readable for a language standard; a
- bit more difficult than K&R Appendix A, perhaps, but not significantly
- so.
- ----
- Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH 45150-2789 513-576-2070
- larry.jones@sdrc.com
- Pitiful. Just pitiful. -- Calvin
-
-
-
-