www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can I work out error: reinterpreting cast from const(ubyte)* to

reply Dr.No <jckj33 gmail.com> writes:
I'm trying to do some hashing at compile time with xxhash 
algorithm but I get this error:

..\..\..\AppData\Local\dub\packages\xxhash-master\xxhash\src\xxhash.d(39,37):
Error: reinterpreting cast from const(ubyte)* to const(uint)* is not supported
in CTFE

this is line 39 
(https://github.com/repeatedly/xxhash-d/blob/master/src/xxhash.d#L39):

 auto srcPtr = cast(const(uint)*)source.ptr;
I'm on Windows 10 64-bit machine.
May 21 2018
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Monday, May 21, 2018 18:13:26 Dr.No via Digitalmars-d-learn wrote:
 I'm trying to do some hashing at compile time with xxhash
 algorithm but I get this error:

 ..\..\..\AppData\Local\dub\packages\xxhash-master\xxhash\src\xxhash.d(39,3
 7): Error: reinterpreting cast from const(ubyte)* to const(uint)* is not
 supported in CTFE

 this is line 39

 (https://github.com/repeatedly/xxhash-d/blob/master/src/xxhash.d#L39):
 auto srcPtr = cast(const(uint)*)source.ptr;
I'm on Windows 10 64-bit machine.
You can't do any kind of pointer manipulaton or related casts in CTFE. So, you can't reinterpet one type as another at compile time. You would need a different hashing algorithm for CTFE - e.g. if(__ctfe) { ... do something to calculate a hash } else { ... calculate the hash the current way } - Jonathan M Davis
May 21 2018