Reputation: 415
When trying to compile my prgram with:
gcc -pedantic -Wall -ansi
I get the warning: warning: statement with no effect
Referring to this line:
for(currentDirection; currentDirection <= endDirection; currentDirection++)
Can anyone help me with this?
Upvotes: 16
Views: 61452
Reputation: 13
In my experience this issue comes up when you do somthing along the lines of
int x = 0;
for(x = 0;x < num; x++){}
When you are declaring your loop and you already initialize your variable, x you don't need to declare it a second time. So either do:
int x = 0;
for(; x < num; x++){}
Or
int x;
for(x = 0; x < num; x++){}
Upvotes: 1
Reputation: 34625
for(currentDirection; currentDirection <= endDirection; currentDirection++)
// ^^^^^^^^^^^^^^^ Its saying about the above statement.
First statement should have an assignment, which is not happening in this case and is the reason for the warning. Make sure currentDirection
is assigned to a valid value or it might have garbage and might later cause issues.
It is similar to when said -
int i = 10 ;
i ; // This statement is valid but has no effect.
Upvotes: 9
Reputation: 318548
currentDirection;
does nothing.
Replace your line with
for(; currentDirection <= endDirection; currentDirection++)
Or, in case you just forgot to initialize the variable:
for(currentDirection = 0; currentDirection <= endDirection; currentDirection++)
Upvotes: 37