[comp.arch] Sorting struct members for alig

wsmith@m.cs.uiuc.edu (03/30/89)

>>In C, it has been a very common idiom to ASSUME that the address of the first
>>member of a struct IS the address of the struct.
>
>Well, according to the December 7, 1988 ANSI C draft, it's not an
>assumption, it's a fact:
	     ^^^^^^^^^^^
>
>	3.5.2.1 Structure and union specifiers
>
>	...A pointer to a structure object, suitably converted, points
					    ^^^^^^^^^^^^^^^^^^
>	to its initial member (or if that member is a bit-field, then to
>	the unit in which it resides), and vice versa. ...

Not so fast.    Notice the phrase: "suitably converted."

The pointer must be cast to the type of the initial member for it to point to
the initial member, so code can be generated to adjust to pointer to point to 
the initial member of the structure instead of the beginning
of the structure.  The offsetting can be "undone" when the pointer
is cast back to point to the original structure type.

Simply passing the pointer as a parameter to the wrong type, uncast, is not 
guaranteed to work.  The reason for this is that the address of something
is not always, on all architectures, the same as a pointer to it.
A common example of this are pointers to functions which I understand
are not straightforward with some compilers.

Bill Smith
wsmith@cs.uiuc.edu
uiucdcs!wsmith