Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!cfctech!teemc!ka3ovk!ki4pv!cdis-1!tanner From: tanner@cdis-1.uucp (Dr. T. Andrews) Newsgroups: comp.lang.c Subject: Re: sizeof a struc field Keywords: sizeof Message-ID: <7633@cdis-1.uucp> Date: 17 Sep 89 20:56:41 GMT References: <7710@microsoft.UUCP> <11086@smoke.BRL.MIL> Organization: Society to Preserve the Sand Gnat Lines: 24 In article <11086@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) writes: ) [ [ #define SIZEGHI sizeof(((struct abc *)0)->ghi) ]... ) doesn't necessarily work. ] Since you're not de-referencing the null pointer, you're going to have a very hard time convincing me that there's an excuse for the above to fail. The same argument applies to the obvious "OFFSET_OF" implementation. ) Review the interminable discussions about use of null pointers. Most of the discussions about NULL pointers have warned of the evils of dereferencing them. It has been noted that a particular object need not actually exist for sizeof() to work. ) #define SIZEGHI (sizeof ((struct abc *)malloc(sizeof(struct abc)))->ghi) And, why not use "blunge()" instead of malloc? We're not going to call malloc() in the sizeof() context. Ah, yes, and we can #define blunge(XX) ((char *)0) /* malloc may return NULL */ and of course we're right back to where we were at the start... -- ...!bikini.cis.ufl.edu!ki4pv!cdis-1!tanner ...!bpa!cdin-1!cdis-1!tanner or... {allegra attctc gatech!uflorida}!ki4pv!cdis-1!tanner