Explicit keyword for "plain old local variable" storage class?

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun May 28 11:34:57 PDT 2006


"Norbert Nemec" <Norbert at Nemec-online.de> wrote in message 
news:e5cl29$iat$1 at digitaldaemon.com...

> Sorry, but I disagree:
> before type inference came along, "auto" already had a meaning. It said:
> "This is *not* a plain old local variable but one that is deleted
> automatically at end of scope." (In your terms, "auto" always meant RAII
> in D)

And before RAII classes came along, 'auto' already had a meaning then too!

'auto' only has special meaning for class references.  auto is also the 
default storage class for regular local variables, and is not a D-ism - it's 
from C.

What I'm proposing is that the class 'auto' is very different from the 
regular 'auto', and as such, they should have different keywords.  The class 
'auto' is more like a separate storage class, and if D gains the ability for 
RAII classes to have lifetimes dependent upon an owning class, that will be 
even more of a reason to have a separate storage class for RAII classes.

> What you suggest here, is to change the meaning of "auto" and then
> introduce a new keyword for what was "auto" before. At the moment,
> "auto" means RAII. What we need is a keyword for non-RAII storage class.

Currently, 'auto' is not consistent - it means one thing for 
non-class-references and another for class references.  What I'm suggesting 
is that "auto" go back to the way it was before RAII classes were 
introduced; that is, it's just a "plain old local variable which is not 
accessible after this scope exits."  With this new behavior, it will work as 
such:

auto int v = 0; // identical to just "int v = 0", just as it is now.
auto w = 5;  // same as it is now.
auto x = new X(); // Type inference; not a RAII class, like now.

And with the new 'raii' keyword (or equivalent):

raii Y y = new Y(); // Same as current "auto Y y = new Y();"
raii z = new Z(); // Type inference with RAII; currently impossible 





More information about the Digitalmars-d mailing list