Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
for (delay_sec; delay_sec > 0; delay_sec--) { delay_ms(1000); }
for (int i = 0; i < delay_sec; i++) { delay_ms(1000); }
void resetChip(int delay_sec) {
for (;delay_sec>0;delay_sec--) { }
for(;;) { }
for(initial;condition;step) instruction;
{ initial; while(condition) { instruction; step; } }
I'm getting a warning 'Statement with no effect' regarding this code:Code: [Select] for (delay_sec; delay_sec > 0; delay_sec--) { delay_ms(1000); }
for ( ; delay_sec > 0; delay_sec--) // omit the initialization expression { delay_ms(1000);}
void resetChip(int delay_sec=10) {
You get the warning 'Statement with no effect' because your code by default doesn't do anything:Code: [Select] for (delay_sec; delay_sec > 0; delay_sec--) { delay_ms(1000); }since delay_sec in your code is initialized as 0 during compilation:Code: [Select]void resetChip(int delay_sec) {So the compiler is like, why should I do a for loop for delay_sec > 0 when delay_sec=0? Your code is legit, it's just the compiler is a bit confused . . .
No-no. There's no "delay_sec=0" code in pomprocker's code; Your brain sees it because you expect it in the begining of the for statement, but there's no such thing. The loop initialisation in the for statement is not valid because it just says the name of the variable, no equal sign, no-nothing The compiler is spot-on.
Quote from: cosminprund on February 18, 2009, 01:33:37 AMNo-no. There's no "delay_sec=0" code in pomprocker's code; Your brain sees it because you expect it in the begining of the for statement, but there's no such thing. The loop initialisation in the for statement is not valid because it just says the name of the variable, no equal sign, no-nothing The compiler is spot-on.The gcc compiler initializes non-initialized variables as 0. But not sure if it's all variables or just non-global or what . . .