Wouldn't this be better with bitfields?

Steven Schveighoffer schveiguy at gmail.com
Thu Jul 4 01:47:52 UTC 2024


On Wednesday, 3 July 2024 at 17:58:53 UTC, Walter Bright wrote:
> On 7/2/2024 8:26 PM, Steven Schveighoffer wrote:
>> Is there a guarantee that the bit pattern will match what the 
>> CPU expects?
>
> As I've written many times, if you stick with uint the layout 
> is portable with every C compiler I know of.

So my response was mostly tongue in cheek, since the dismissal of 
previous concerns about exact layout was always "just use 
std.bitmanip". I have since relented that I'm OK with the C 
compatibility as long as there is some expectation that "as long 
as you use uint, it's fine".

But... I'm thinking now, why not just specify that? If you use 
uint, this is the explicit layout, and any C compiler that 
doesn't implement that mechanism, D does not support bitfield 
compatibility.

That would go a long way to alleviating any concerns that 
portability would be based on the whim of some C compiler.

This should be fine, because, as you say, everyone already does 
it that way. D has the opportunity to make this official.

-Steve


More information about the Digitalmars-d mailing list