Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!deccrl!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!stc!graham From: graham@tcom.stc.co.uk (Graham Bardsley) Newsgroups: comp.lang.c Subject: Taking address of array Summary: offset Message-ID: <1991Apr9.172534.28982@tcom.stc.co.uk> Date: 9 Apr 91 17:25:34 GMT Sender: news@tcom.stc.co.uk (USENET News System) Organization: NT Europe Ltd, New Southgate, London, N11 1HB Lines: 35 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 I think I'm just worried that a lot of compilers might throw it out as being bad C. The macros are part of a portability layer so the idea is to have some macros which will work nomatter what compiler is being run. If the compiler doesn't support the offset macro directly (like ANSI) then something like the above will be substituted. -- Graham Bardsley,NT Europe Ltd,Oakleigh Road South,New Southgate,London, N11 1HB ..{uunet,mcsun}!ukc!stc!graham Tel: +44 81 945 3799 And My long-winded ISO10021 address is probably something like: G=/I=G/S=Bardsley/OU=lon4021/O=stc telecommunications/P=stc plc/A=gold 400/C=GB