How is this c function decrementing my counter?
I have the following code:
int i;
for(i=0;i<2;i++) {
...
printf("i = %d\n",i);
rtdb_pull(rtdb, buf, &ncenter);
printf("i = %d\n",i);
...
}
When I run it, it goes through just fine while i=0, but as soon as i=1,
the rtdb_pull function seems to decrement the counter, so I end up stuck
in a loop. How is this possible? I don't pass i to rtdb_pull, nor does
rtdb_pull use a variable called i.
If I do this, everything works just fine:
int i;
for(i=0;i<2;i++) {
...
printf("i = %d\n",i);
int j = i;
rtdb_pull(rtdb, buf, &ncenter);
i = j;
printf("i = %d\n",i);
...
}
For the record, I am using gcc 4.7.3 on Ubuntu 13.04 and compiling with
ANSI c. I do not get any related warnings from the compiler.
No comments:
Post a Comment