Typical security issues in C++: why the GC isn't your enemy

Dom DiSc dominikus at scherkl.de
Fri Dec 9 09:43:36 UTC 2022


On Thursday, 8 December 2022 at 23:30:56 UTC, Timon Gehr wrote:
>>> A particularly egregious case is the do-while loop:
>>>
>>> do{
>>>      int x=4;
>>>      if(condition){
>>>          ...
>>>          x++;
>>>      }
>>>      ...
>>> }while(x<10); // error
>>> ```
>>>
>>> Just... why? x)
>> 
>> Because we love to annoy people.
>> 
>
> Well, for D specifically, I hope the answer is just that the 
> reason is that C does it this way.

Well, declaring variables within a loop is just awful style, 
don't do that!
And it will also not work with for-loops, but may be somewhat 
more obvious for humans:

for(int i = 0; i < x; ++i) // error: x undeclared
{
    int x = 10;
    ...
}




More information about the Digitalmars-d mailing list