memory safety checks and trust

Walter Bright newshound2 at digitalmars.com
Tue Apr 14 09:56:39 UTC 2020


On 4/13/2020 2:03 AM, Timon Gehr wrote:
>> Consider:
>>
>>    @system int* pumpkin(int i) { return &i; }
>>
>> Should that give an error or not?
>> ...
> 
> I don't see why not.

I've written code like that to get the stack pointer value.

As to the other case, to my mind putting the address of a stack local into a GC 
allocated object is highly suspicious:

1. it is very very easy to do it unintentionally

2. GC objects tend to be intended to outlast a function, yet the stack address 
will not, so why is this a GC allocated object, as opposed to, say, an RAII 
object or even a stack allocated object?

I don't know what Adam's actual use case for this is, but I would reject such 
code because of (1) and (2) even for @system use in any project I have control over.

Therefore, whether you agree with where I drew the line or not, this is a 
subjective decision not an objective one.


More information about the Digitalmars-d mailing list