compile time 'address'

Steven Schveighoffer schveiguy at gmail.com
Thu Nov 29 20:22:16 UTC 2018


On 11/29/18 2:16 PM, Stanislav Blinov wrote:
> On Thursday, 29 November 2018 at 18:49:27 UTC, Steven Schveighoffer wrote:
> 
>> I don't think it would be a huge stretch to apply this same property 
>> to function locals, but it would require an enhancement request.
>>
> 
> 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.

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?

-Steve


More information about the Digitalmars-d mailing list