C bitfields guarantees
Timon Gehr
timon.gehr at gmx.ch
Wed Jul 10 00:44:41 UTC 2024
On 7/9/24 02:29, Walter Bright wrote:
>
> Let's say Bob (poor Bob) needs to convert 20,000 lines of C code to D. I
> know you've done some of this yourself! Bob doesn't want to go through
> it line by line. Isn't it nice for Bob if it "just works"?
It won't, some edits will be necessary.
> If all those
> data declarations just work? Especially if the result still has to be
> compatible with the files that C code wrote out?
>
> But what if the compiler says "Bob, you can't lay out a bitfield like
> that!"
The compiler should simply say: "Bob, are you sure you want to lay out a
bitfield like this?" If Bob is comfortable with it, he can add
`extern(C)` and move on.
> Or worse, it lays out the bitfield into a portable (but
> different) layout.
Well I think this is not an option.
> Then it doesn't just work, Bob has got some debugging
> to do (while Bob curses D and me), and Bob's got to figure out an
> alternative. Who wants to do that? Not Bob. Not me. Not nobody not nohow.
As far as I am concerned, this is an irrelevant straw man. I don't want
this. I never suggested anything that would cause this. It's pure FUD.
Similarly, I don't want to go chasing down subtle differences in
behavior/cache performance etc. between platforms. Portability may be
important. It shouldn't be insane by default, it should be insane by
choice. Informed consent.
Especially given that bitfields have a "much nicer syntax" than
alternative approaches. It's not nice to hand out a footgun disguised as
candy.
More information about the Digitalmars-d
mailing list