Neat project: add pointer capability to std.bitmanip.bitfields

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 4 19:57:01 PST 2015


On Saturday, 5 December 2015 at 00:33:15 UTC, Vladimir Panteleev 
wrote:
> On Friday, 4 December 2015 at 23:38:08 UTC, deadalnix wrote:
>> On Friday, 4 December 2015 at 10:31:19 UTC, Vladimir Panteleev 
>> wrote:
>>> I realized this was off after posting but I don't understand 
>>> your reasoning either. The size and alignment just put a 
>>> bound on the number of bits, but without verification in the 
>>> setter you can't be sure, right?
>>
>> If one of the bit within the alignment is not 0, that mean you 
>> did something unsafe previously to create that pointer.
>
> But this only applies to ... pointers to pointers, right? In D, 
> only pointer variables have to be aligned to maintain safety, 
> and even then that only applies to GC pointers (a C function 
> may return an "unaligned" pointer pointer). struct { align(1): 
> ubyte a; int b; } is still quite safe, and so is interpreting a 
> pointer into an array of ubytes as an uint.

No a pointer has some alignment that depends on whatever data it 
points to. You cannot steal any bits for a char* (and 
taggedPointer will reject it) you can steal one bit from a 
short*, and so on. This is checked statically.


More information about the Digitalmars-d mailing list