Taking address of array
Marc Auslander
marc at watson.ibm.com
Thu Apr 11 22:29:24 AEST 1991
In article <1991Apr9.172534.28982 at tcom.stc.co.uk> graham at 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 <marc at ibm.com>
More information about the Comp.lang.c
mailing list