Wouldn't this be better with bitfields?
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Thu Jul 4 15:18:54 UTC 2024
On 04/07/2024 1:47 PM, Steven Schveighoffer wrote:
> 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
As a consequence it does mean that you shouldn't be doing things like
tagged pointers with it.
And that's a problem since pretty much all new cpu designs are 64bit.
More information about the Digitalmars-d
mailing list