Wouldn't this be better with bitfields?
Mike Parker
aldacron at gmail.com
Tue Jul 9 11:58:14 UTC 2024
On Tuesday, 9 July 2024 at 10:57:02 UTC, claptrap wrote:
>
> You have completely missed the point. Struct layout doesn't
> change, it's fixed, it doesn't depend on what C compiler is
> attached.
The layout is fixed, but alignment and padding are implementation
specific.
>
> It's not C-compatibility, but letting the under specification
> of C bitfields basically infect D. Its the tail wagging the
> dog. Or leaky implementation. If I have a D program that links
> a dll or static lib also written in D, they could have
> incompatible bitfield layouts.
>
> You could fix this by specifying the layout for D bitfields,
> and using extern(C) when compatibility with the relevant C
> compiler is required. D already does that for classes and
> functions...
`extern(C)` does not affect the layout of anything, as far as I
know. It only impacts name mangling and calling convention. Using
it to change layout would be a new feature.
When I worked on Derelict and BindBC, I would have loved to have
had bitfields in D. And I would have expected them to line up
with the associated C compiler out of the box, because that's
what already happens with structs.
More information about the Digitalmars-d
mailing list