Discussion Thread: DIP 1035-- at system Variables--Community Review Round 2

Paul Backus snarwin at gmail.com
Sat Feb 27 15:55:14 UTC 2021


On Saturday, 27 February 2021 at 15:21:41 UTC, Steven 
Schveighoffer wrote:
> On 2/27/21 8:32 AM, Paul Backus wrote:
>> You *can* get the compiler to treat any value as unsafe by 
>> overlapping it with a pointer; e.g.,
>> 
>> struct Unsafe(T)
>> {
>>      union Storage { T value; void* dummy; }
>>      Storage storage;
>>      ref T get() { return Storage.value; }
>>      /* ... */
>> }
>> 
>> But this introduces memory overhead for any T smaller than a 
>> pointer, which is not ideal.
>
> Better mark that get as @system, or it can be used in @safe 
> code.

It's in a template, so it will be inferred as @system.


More information about the Digitalmars-d mailing list