Portability question

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Tue Nov 5 14:59:43 AEST 1985


>     struct x {something};
>     struct x *ip;
> 
>     struct
>       {
>           struct x a;
>           struct x b;
>           struct x c;
>           struct x d;
>           struct x e;
>       }
>           index;
> 
>     y = index.a.whatever;
>     z = index.c.whatever;
> 
>     ip = (struct x *)&index;
>     ...
>     w = ip[i].whatever;

That is not guaranteed to work, primarily because there
may be padding between the members of `index'.  However,
it is unlikely that there would be padding since it
would normally be contained within a `struct x'.

Consider the following less elaborate code:

	struct x {something};

	struct x array[5];
	#define	a array[1]
	#define	b array[2]
	#define	c array[3]
	#define	d array[4]
	#define	e array[5]

	y = a.whatever;
	z = c.whatever;
	...
	w = array[i].whatever;



More information about the Comp.lang.c mailing list