Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!decwrl!labrea!sri-unix!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: sizeof( _variable_ ) Message-ID: <191@quintus.UUCP> Date: 25 Jul 88 04:06:20 GMT References: <1264@bc-cis.UUCP> <529@proxftl.UUCP> <6089@chinet.chi.il.us> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Distribution: na Organization: Quintus Computer Systems, Inc. Lines: 22 In article <6089@chinet.chi.il.us> les@chinet.chi.il.us (Leslie Mikesell) writes: >In article <529@proxftl.UUCP> bill@proxftl.UUCP (T. William Wells) writes: >>What is happening is this: C defines the size of a type as if it >>were part of an array. > >The point of this is that you can access corresponding elements of successive >structures in an array by adding sizeof(struct) to a pointer to the >previous element. There are two ways of using 'sizeof': sizeof -- not using official and sizeof () -- nonterminals The connection between sizeof () and arrays appears to me to mean that sizeof () is redundant *IN SOME IMPLEMENTATIONS*: #define SIZEOF(Type) ( (char*)&1[(Type *)0] - (char*)&0[(Type *)0] ) This would have worked on the PDP-11, /370, VAX, 3B, &c, and works on Suns. [The offsetof() macro works much the same way.] Don't get me wrong: sizeof is a Good Thing because it is much clearer and more portable than this sort of magic. The question is whether sizeof () was originally foresight or oversight? Another one is: in which implementations does SIZEOF not work?