Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!munnari.oz.au!cs.mu.oz.au!ok From: ok@cs.mu.oz.au (Richard O'Keefe) Newsgroups: comp.lang.c Subject: Re: how about sizeof(((type *)1)->member) ? Message-ID: <2582@munnari.oz.au> Date: 30 Oct 89 03:26:51 GMT References: <1989Oct27.141015.20578@talos.uucp> <2550111@hpisod2.HP.COM> Sender: news@cs.mu.oz.au Lines: 13 The problem is how to replace sizeof (((struct foo *)(0))->member) in an ANSI-portable way. Since malloc() must return a pointer which satisfies all alignment requirements, could we not use #define fieldsize(Foo,Member) sizeof \ (((struct Foo *)malloc(sizeof (struct Foo)))->Member) Since the expression isn't going to be evaluated, nothing will be allocated. If it _were_ evaluated, the expression would be valid, so a compiler has nothing to complain about, or has it?