Taking address of array
Graham Bardsley
graham at tcom.stc.co.uk
Wed Apr 10 03:25:34 AEST 1991
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 <graham at tcom.stc.co.uk> 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
More information about the Comp.lang.c
mailing list