🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #20596

Re: Sorting struct members for alig

#20596
From: wsmith
Date: Thu, 30 Mar 1989 04:05
32 lines
1747 bytes
>>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
Technical Details
Message-ID: <3300061@m.cs.uiuc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc!uxc.cso.uiuc.edu!m.cs.uiuc.edu!wsmith
References: <1315@auspex.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc!uxc.cso.uiuc.edu!m.cs.uiuc.edu!wsmith
From: wsmith@m.cs.uiuc.edu
Newsgroups: comp.arch
Subject: Re: Sorting struct members for alig
Message-ID: <3300061@m.cs.uiuc.edu>
Date: 30 Mar 89 04:05:00 GMT
References: <1315@auspex.UUCP>
Lines: 32
Nf-ID: #R:auspex.UUCP:1315:m.cs.uiuc.edu:3300061:000:1279
Nf-From: m.cs.uiuc.edu!wsmith    Mar 29 22:05:00 1989