For-loop problem

Jun 30, 2011 at 5:49pm
I'm getting seg-fault in a for-loop like this, where I need to change the starting point within the body.

Is that accepted/allowed?

I'm using gcc version 4.4.3

Thanks!

1
2
3
4
5
6
7
8
9
for (s=N; s>= 0; s--) {

        { some code here }

        if (condition)
                --N;

        // NOTE: it's *never* N < s
}
Jun 30, 2011 at 6:22pm
Segfaults happen when you use invalid pointers. If your code has a problem, it's in the "some code here" part. Note though that s=N happens only once before the loop starts. Any changes to N afterwards has no effect on s.
Jun 30, 2011 at 6:28pm
Use the debugger. Step through the code one line at a time. Look at the values of variables as you step. Nobody here is going to be able to help much unless you post something that is more complete.
Topic archived. No new replies allowed.