Wouldn't this be better with bitfields?

Dukc ajieskola at gmail.com
Sun Jul 7 06:17:27 UTC 2024


On Sunday, 7 July 2024 at 03:58:50 UTC, Walter Bright wrote:
> On 7/6/2024 11:05 AM, Dukc wrote:
>> Actually this is an analogy I want to push. Ask yourself, why 
>> is `long` defined as exactly 64 bits in D? Why isn't it 
>> defined to have the same size as associated C `long`?
>
> Because a 32 bit C long is useless. It's a vestigial remainder 
> from 16 bit programming.
>
> Sensible C programmers use "long long" instead.

Yes. In the same way:

Implementation defined behaviour for bitfields is useless. It's 
there just for backwards compatibility for times when there was 
no C standard for it, or whatever.

Sensible C programmers stick with aligning the start of the 
bitfield with alignment of the bitfield type, which makes the 
layout predictable and lets `std.bitmanip` bitfield to be used 
for interfacing with it.


More information about the Digitalmars-d mailing list