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

Timon Gehr timon.gehr at gmx.ch
Fri Dec 9 10:54:54 UTC 2022


On 12/9/22 10:43, Dom DiSc wrote:
> 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!

Nonsense.

> 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;
>     ...
> }
> 
> 

What is your point? That's a completely different case, you are 
accessing `x` before it is even declared.


More information about the Digitalmars-d mailing list