Re: style: structures

2024-10-08 Thread Mouse
> C99 Sec. 6.7.2.1 `Structure and union specifiers', clause 13, p. 103: > [...] Ah! Thank you. Yes, that is what I was looking for. (And the "vice versa" answers the question I asked in my previous mail.) > But don't use casts for this -- use container_of, which is more > flexible and checks t

Re: style: structures

2024-10-08 Thread Mouse
>>> [...], 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 pr

Re: style: structures

2024-10-08 Thread Taylor R Campbell
> Date: Tue, 8 Oct 2024 08:50:00 -0400 (EDT) > From: Mouse > > > [...], 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 structur

Re: style: structures

2024-10-08 Thread tlaronde
On Tue, Oct 08, 2024 at 01:15:54PM +, Taylor R Campbell wrote: > > Date: Tue, 8 Oct 2024 10:06:39 +0200 > > From: tlaro...@kergis.com > > > > In the style file, for structures, the emphasis is put on alignment in > > order to not waste memory because of undue padding. > > > > Shouldn't an exc

Re: style: structures

2024-10-08 Thread tlaronde
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? > >

Re: style: structures

2024-10-08 Thread Taylor R Campbell
> Date: Tue, 8 Oct 2024 10:06:39 +0200 > From: tlaro...@kergis.com > > In the style file, for structures, the emphasis is put on alignment in > order to not waste memory because of undue padding. > > Shouldn't an exception been mentionned concerning structures that may be > derived from a base st

Re: style: structures

2024-10-08 Thread Mouse
> [...], 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'

Re: style: structures

2024-10-08 Thread Martin Husemann
On Tue, Oct 08, 2024 at 10:06:39AM +0200, tlaro...@kergis.com wrote: > Shouldn't an exception been mentionned concerning structures that may be > derived from a base structure, so that the first member of the derived > structures is a base structure, using the C standard guaranteed property > that

style: structures

2024-10-08 Thread tlaronde
In the style file, for structures, the emphasis is put on alignment in order to not waste memory because of undue padding. Shouldn't an exception been mentionned concerning structures that may be derived from a base structure, so that the first member of the derived structures is a base structure,