dmd casts but ldc doesn't, and doesn't work in template in dmdm

Mike B Johnson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 4 18:14:31 PDT 2017


On Monday, 5 June 2017 at 00:56:52 UTC, Jonathan M Davis wrote:
> On Monday, June 05, 2017 00:18:04 Mike B Johnson via 
> Digitalmars-d-learn wrote:
>> [...]
>
> I assume that guid is a string or array of byte or somesuch? If 
> it's an array of byte or char, then you can probably do
>
> auto bytes = cast(byte[16])guid[0 .. 16];
>
> I doubt that it will work with CTFE though, because this is 
> basically a reinterpret cast, and CTFE gets picky about casts 
> like that. If you need to do something like that in CTFE, 
> you'll probably need to use if(__ctfe) to add a branch that 
> does this it in a for loop or something without any casts.
>
> Also, you probably want ubyte, not byte. byte is signed, so it 
> really only makes sense to use it as an integral value that 
> holds [-128, 128] rather than for an actual byte value.
>
> - Jonathan M Davis

Guid is a struct and I am trying to get the "bytes" of the 
struct" to get the guid bytes. It is quicker than accessing all 
the elements one at a time.


More information about the Digitalmars-d-learn mailing list