4 ms·
I misremembered my C89 gripe! The issue was that the following is not allowed: for (int i = 0; // ... Forcing you to write int i; for (i = 0; //
by strbean 6y ago
I misremembered my C89 gripe! The issue was that the following is not allowed:
for (int i = 0; // ...
Forcing you to write
int i;
for (i = 0; // ...
The real annoyance here is that you can't restrict the scope of a variable you need initialized at the start of a for loop to the loop block. It's all fine and dandy when you are just using `i` (and never miss resetting it, or use it somewhere expecting it to be one thing and have it end up being another). When you have several complex loops in a function, it can be a bit aggravating.
(Declaring variables willy nilly anywhere in a block is nice too)
- dllthomas 6y agoAh, yeah. There shouldn't be any runtime difference if you don't leak the address of `i` somewhere the compiler can't see, which should be uncommon for an iterator. But I agree it's awkward. You can wrap the whole thing in an extra block, so at least you don't have to hoist `i` to the top of the function. > (Declaring variables willy nilly anywhere in a block is nice too) You can always introduce another block, although it's not uncommon that that's harder on legibility than just hoisting.