Why can't we make reference variables?
Era Scarecrow
rtcvb32 at yahoo.com
Tue Aug 28 20:17:38 PDT 2012
On Wednesday, 29 August 2012 at 02:57:27 UTC, Era Scarecrow wrote:
> You would need a flag added to EVERY variable and item to
> specify if it was stack allocated or not. Otherwise it would be
> quite annoying to deal with. The compiler has to work blindly,
> assuming everything is correct. You can ref what you've been
> given but making more permanent references aren't possible
> without bypassing the safeguards.
To add on to this a little.. If you can only ref by calling, you
ensure the variable is alive/valid when you are calling it
regardless if it's stack or heap or global (But can't ensure it
once the scope ends). Making a reference as a variable modifier
won't work, but using a pointer you're already going lower level
and it's all up to you the programmer to make sure it's right.
I think that's right; Otherwise ref wouldn't be allowed in @safe
code (at all).
More information about the Digitalmars-d
mailing list