Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbatt!cbosgd!danews!lvc From: lvc@danews.UUCP (Larry Cipriani) Newsgroups: net.lang.c Subject: Re: Re: Sizeof structure members Message-ID: <153@danews.UUCP> Date: Tue, 29-Jul-86 16:13:35 EDT Article-I.D.: danews.153 Posted: Tue Jul 29 16:13:35 1986 Date-Received: Thu, 31-Jul-86 04:39:02 EDT References: <148@danews.UUCP> <444@dg_rtp.UUCP> Organization: AT&T Bell Labs, Columbus OH Lines: 26 > > [How does one take sizeof a struct member without an instance of it?] > > .... > This solution is fairly portable, and may even be legal: > > struct s {char a[3];}; > void main(){ > printf( "%d\n", sizeof( ((struct s *)0)->a ) ); > } > > It works on a at least a couple of machines, and lint doesn't complain. > It may be argued that it is not legal, since it is dereferencing the > null pointer. On the other hand, sizeof is guaranteed not to evaluate > the object being sizeofed, and to only calculate resulting types, not > values. It's issues like these that give language lawyers headaches, > right? > > Wayne Throop !mcnc!rti-sel!dg_rtp!throopw It works on my machines Sys 5 Rel 2 3B[2/5/20]s. I like this very much! Thanks a lot. I would have said thanks a week ago but danews is down more than it is up. -- Larry Cipriani AT&T Network Systems danews!lvc "Nothing is worse than an itch you can never scratch."