auto -> auto & var

Georg Wrede georg.wrede at nospam.org
Fri Mar 17 13:01:32 PST 2006


Lionello Lunesu wrote:
> "Kramer" <Kramer_member at pathlink.com> wrote in message 
> news:duspas$2dfo$1 at digitaldaemon.com...
> 
>> I keep tripping myself over the double meaning of auto.  I know it
>>  shouldn't be that difficult to remember that auto means type
>> inference and also stack allocation/RAII, but does it have to be
>> that way?
> 
> Walter explained it: it does not have two meanings. The "auto" merely
>  notifies the compiler (or lexer, I don't know) that it's a
> declaration and a variable name will follow.
> 
> When the compiler encounters "auto x" it knows "x" is a variable.
> Since "auto x" doesn't mention a type, it'll be derived.. Same thing
> for "static x", x must be a variable, but there's no type so it'll be
> derived.

While Walter is right, this still _seems_ like two separate things, 
especially for those new to the language. Whether new to programming or 
just new to D.

Pascal used to make a fuss about the difference between a Function and a 
Procedure. No C programmer couldn't care less about that difference. But 
the main point is that having two separate names for [the same or 
different things, depending on who you ask], might not always be bad for 
your health.

Two separate words would ease learning D, and make it clearer which the 
programmer meant. This is especially important for expedient debugging.



More information about the Digitalmars-d mailing list