DMD 0.174 release
Walter Bright
newshound at digitalmars.com
Fri Nov 17 12:20:18 PST 2006
Stewart Gordon wrote:
> Walter Bright wrote:
>> Stewart Gordon wrote:
>>> Moreover, this whole way of putting things can lead one to wonder
>>> whether variables declared in the body are reinitialized each
>>> iteration....
>>
>> Why? A declaration is just like an assignment statement. It is
>> executed when it appears. If it appears in a loop, it is executed each
>> iteration of that loop.
>
> True in general, but....
>
> - in general, a declaration such as
>
> int x;
>
> doesn't look like an assignment statement
Since D has default assignment in declarations, it is one. It behaves
the same way in C++ (for types that have default constructors). D isn't
doing anything weird here.
> - the idea of the same variable being declared multiple times in the
> same instance of being in the same scope is alien to many
? You cannot declare the same variable multiple times in the same scope.
> - there are also static local variables, which aren't reset each time
Again, this behaves just like C++, and should not be surprising.
> Moreover, your claim that the _body_ of a for loop doesn't create a
> scope would also mean that ScopeGuardStatements and scope (fka auto)
> object references within the body are not processed at the end of each
> iteration, but saved until the end of the whole for loop. Absolutely
> not the behaviour I'm experiencing.
The for statement itself generates a scope, not the { }. This behaves
exactly like the for statement in C++.
More information about the Digitalmars-d-announce
mailing list