Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!bywater!scifi!watson!arnor!arnor!marc From: marc@watson.ibm.com (Marc Auslander) Newsgroups: comp.lang.c Subject: Re: Taking address of array Message-ID: Date: 11 Apr 91 12:29:24 GMT References: <1991Apr9.172534.28982@tcom.stc.co.uk> Sender: news@watson.ibm.com (NNTP News Poster) Organization: IBM T.J. Watson Research Center, Hawthorne, New York Lines: 37 In-Reply-To: graham@tcom.stc.co.uk's message of 9 Apr 91 17:25:34 GMT Nntp-Posting-Host: marc In article <1991Apr9.172534.28982@tcom.stc.co.uk> graham@tcom.stc.co.uk (Graham Bardsley) writes: >I've got some macros which calculate the address of an offset of a structure >(stolen from the X11R4 src), and some of the structures I'm using them have >character arrays: >struct small_struct >{ > int x; > char y[100]; >}; >What I want to know is, if the macro calculates: >((int) (((char *) (&(((struct small_struct*) 0)->y))) - ((char *) 0))) >Is the value of this a valid construct which will calculate the offset of y on >most traditional C compilers, since on the standard Sun C compiler it throws >out the warning: > & before array or function: ignored The Risc System/6000 compiler also issues a warning message and compiles. Note that if you have a macro which takes addresses of things and you need to pass it an array, a work around is to pass the first element. In your example: ((int) (((char *) (&(((struct small_struct*) 0)->y[0]))) - ((char *) 0))) is correct C. -- Marc Auslander