second draft: add Bitfields to D
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Sat Apr 27 07:12:21 UTC 2024
On Friday, April 26, 2024 9:26:06 AM MDT Steven Schveighoffer via
dip.development wrote:
> On Tuesday, 23 April 2024 at 01:01:11 UTC, Walter Bright wrote:
> > https://github.com/WalterBright/documents/blob/dcb8caabff76312eee25bb9aa05
> > 7774d981a5bf7/bitfields.md
> Suffers from the same major problem as last time - nobody is
> going to be using C bitfield structs from D, yet we are
> inheriting all the problems. Keeping C compatibility is
> meaningless. We should pick one way and do it that way for D
> bitfields.
C compatability matters a lot for importC and for C bindings in general -
not that we have to have a bitfields feature for general D which matches
that, but if we don't have a way to match what C does, then we have trouble
creating bindings for C code that uses bitfields. extern(C++) code
potentially needs the same thing.
Personally, binding to C is the primary way that I've ever had to deal with
bitfields, and not having the ability to do that has made dealing with such
bindings... interesting.
Now, if we want to do something like have extern(C) bitfields and extern(D)
bitfields so that we can have clean and consistent behavior in normal D
code, I'm perfectly fine with that, but I don't agree at all that binding to
C doesn't matter. For me at least, that's the primary place that bitfields
matter, particularly since I can use other solutions in D if need be,
whereas if a C API is designed to use bitfields, then you kind of need
support for that in D if you want the bindings to work correctly.
> Have you considered that people might build some libraries with
> ldc, but build applications with dmd? If LDC picks one mechanism
> for laying out bitfields, but DMD picks a different one, then
> what happens when you try to use the two together? Do we really
> want to make D incompatible with itself?
Completely aside from this specific issue, isn't it already the case that
you can't mix code built with different D compilers? I didn't think that
there was any guarantee of ABI compatibility across compilers, and I would
fully expect there to be trouble if I built parts of my code with one
compiler and other parts with another. I typically get linker errors at work
if I fail to clean out the build files when switching between dmd and ldc.
- Jonathan M Davis
More information about the dip.development
mailing list