tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: style: structures



On Tue, Oct 08, 2024 at 08:50:00AM -0400, Mouse wrote:
> > [...], using the C standard guaranteed property that the address of
> > the first member is the address of the structure, allowing to cast
> > pointers in order to operate whether on the base structure or on the
> > derived structure?
> 
> Which standard promises this, and what exactly does it promise?  I've
> been looking through C99 and the closest I've found so far is 6.5.2.3
> #5, which is not quite the same:
> 

K & R, "The C Programming Language", second edition (english version),
p 213:

	The members of a structure have addresses increasing in the
	order of their declarations. A non-field member of a structure
	is aligned at an addressing boundary depending on its type,
	therefore, there may be unnamed holes in a structure. If a
	pointer to a structure is cast to the type of a pointer to its
	first member, the result refers to the first member.

-- 
        Thierry Laronde <tlaronde +AT+ kergis +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index