0

For some reason I'm getting an error: statement with no effect on this statement.

for (j = idx; j < iter; j + increment) {
    printf("from loop idx = %i", (int)idx);
    punc(ctxt, j);
}
1
  • Is it really an error? Not a warning? Commented Sep 15, 2011 at 20:59

5 Answers 5

9

You probably meant to write j += increment instead of j + increment.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks that's exactly it. ... I feel ashamed that I didn't caught it. must be tired
5

I think you meant j += increment, as j + increment doesn't actually alter j or indeed have any side effects at all - it is a statement with no effect, which is what the compiler is telling you

2 Comments

And it is probably even optimized out by the compiler so it doesn't do anything at all, not even evaluate.
If increment is added to j in a forest and nobody hears noise from poor shielding in the on-board soundcard, did it really make a sound?
4

Replace

j + increment

With

j += increment

Comments

1

You are getting that as an error? How cool, I wish my compiler did that. Basically j + increment will return the sum of those two, but j won't get modified so your loop would probably run forever.

1 Comment

If you have gcc, the -Werror option (with -Wall) turns warnings to errors; -Werror=unused-value turns the specific warning in this question to an error.
0

It's clear you meant +=, but in the case that isn't true, the 'volatile' qualifier should prevent warnings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.