Path: utzoo!utgpu!water!watmath!clyde!att!alberta!ubc-cs!uw-beaver!cornell!mailrus!uflorida!novavax!proxftl!bill From: bill@proxftl.UUCP (T. William Wells) Newsgroups: comp.std.c Subject: Re: The offsetof macro Message-ID: <643@proxftl.UUCP> Date: 28 Aug 88 23:20:21 GMT References: <16490006@hpcllca.HP.COM> Reply-To: bill@proxftl.UUCP (T. William Wells) Organization: Proximity Technology, Ft. Lauderdale Lines: 29 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <16490006@hpcllca.HP.COM> walter@hpcllca.HP.COM (Walter Murray) writes: : I think this may have been discussed a few months ago in comp.lang.c. : If so, would someone please mail or post the consensus that was : reached? : : The offsetof macro is supposed to expand to an integral constant : expression. There are strict rules about the operands and casts : that can be used in an integral constant expression, so, for : example, an expression containing "(type *)0" wouldn't be legal. : Using such an illegal expression in a place where an integral : constant expression is required, such as a case label expression, : would violate a constraint and would seemingly require a diagnostic : to be produced. : : So what is a valid way to define offsetof? There isn't any portable way that I can think of. I wouldn't be surprised if that is why it is defined in a header file where the compiler is free to define it any way it wants. For example, it could be defined as: #define offsetof(type,mem) __offsetof_kludge(type,mem) and, could then treat __offsetof_kludge somewhat as it might treat sizeof. --- Bill novavax!proxftl!bill