compile time 'address'

Stanislav Blinov stanislav.blinov at gmail.com
Thu Nov 29 21:00:57 UTC 2018


On Thursday, 29 November 2018 at 20:22:16 UTC, Steven 
Schveighoffer wrote:

>> This compiles since 2.069.2 (according to run.dlang.io):
>> 
>> void main() {
>>      auto c0 = 1;
>>      auto c1 = 2;
>>      static assert(&c0 == &c0);
>>      static assert(&c0 != &c1);
>> }
>> 
>> I wonder if that is a bug, or that the original question not 
>> compiling is :D
>
> I think the issue is that D is expecting you to be able to use 
> the value pointed at possibly in the function, which would 
> normally be fully available at CTFE (the two variables are 
> runtime variables).
>
> There's no way to accept a pointer that can't be used, just the 
> value of the pointer checked.

Yeah, but this one seems a bit deliberate. The asserts hold, but 
you can't e.g.

enum diff = &c0 - &c1; // 'c0' can't be used at compile time

> I'm not sure how it would work exactly. I suppose you could 
> accept void *, I don't know if it's possible to recast in CTFE?

It isn't.


More information about the Digitalmars-d mailing list