auto -> auto & var
John C
johnch_atms at hotmail.com
Fri Mar 17 13:21:35 PST 2006
"Georg Wrede" <georg.wrede at nospam.org> wrote in message
news:441B23AC.7050905 at nospam.org...
> 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.
There won't be a need for two keywords when Walter implements the new
stack-allocation syntax. I think this was it:
void main() {
Stream theDaVinciCode = File("thedavincicode.txt");
theDaVinciCode .readLine(); // read the first line
// close theDaVinciCode immediately
}
More information about the Digitalmars-d
mailing list