3 ms·
I'd suggest that, if a variable with an undefined value is a valid state for the program, the declaration is in the wrong place. How about this alternative?
by ant512 13y ago
I'd suggest that, if a variable with an undefined value is a valid state for the program, the declaration is in the wrong place. How about this alternative?
int dec(int a, int condition) {
if (condition) {
int temp = 0;
//compute something here in a loop
while (temp < a) {
a -= (temp++);
}
}
return a;
}
- optymizer1 13y agoThat's the obvious next step, but it's not valid C89 and that may or may not be relevant for people doing embedded programming. Personally, I'm all for using newer standards and declaring variables locally when it makes sense. Sometimes I like to see all variables at the top of the function though.