On Thursday, 26 May 2016 at 07:51:46 UTC, Era Scarecrow wrote:
If the ptr is at offset 0, we declare it first, otherwise second, simple... Except this fails since "no property 'offsetof' for type 'void*'". SO... I make a template to test for it instead.


Built-in arrays are kinda magical and thus their members aren't ordinary members you can inspect like that.

    return *(cast(size_t*) &arr) != 1;

And I'm pretty sure that cast is illegal in CTFE. Perhaps the bug here is that dmd isn't throwing an error when it is supposed to...

The value being compared gives 0 when I try it, which wouldn't make sense for either .length or .ptr.

 Am i going about this the wrong way?

I don't think there's a need for a test because the ABI spec says length is always defined to be at offset zero anyway:

http://dlang.org/spec/abi.html#arrays

If you want to test it, a runtime assert would probably be enough, at least then it won't do the wrong thing and your message can tell the user to recompile.

Runtime assert is prolly better anyway just in case ctfe disagrees with the execution platform.

Reply via email to