[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: gcc: A while Loop Always Skips its first Statement.



On 20/08/2010 3:01 p, Martin McCormick wrote:
I have written some C code that appeared to be good until I put
a while statement in to one of the modules and then all went to
at least Purgatory. It all compiles beautifully but I was
alerted to something terribly wrong when the program began
misbehaving. I can't even say that it is flaky because it does
exactly the same wrong things every time without fail.

	There is a variable I call NEXTSYS which is boolean and
my while statement now looks like:

while (NEXTSYS) { /*code to execute if NEXTSYS does not = 0*/
C statements (It doesn't seem to matter what statements);
} /*code to execute if NEXTSYS does not = 0*/

	What happens every time is that gdb traces perfectly up
to the while statement, skips it, and executes the statements
inside the braces. After that, it is in the while loop and
execution looks normal but the damage is already done. I have
also seen it trace the wile statement and then skip the next
executable statement in the loop no matter what it is.

	Reading about the while loop tells me that the statement
after while must be true to execute. If I put a boolean variable
inside the statement as in (NEXTSYS) does that make a true
statement if it is not 0 and false if it is?

Thanks for any constructive answers.
Martin McCormick WB5AGZ  Stillwater, OK
Systems Engineer
OSU Information Technology Department Telecommunications Services Group


Not a question for this list but
1. Is there any statement in the while loop that changes NEXTSYS? (or better still, send any statement that has NEXTSYS in it while inside the loop)
2. Is there any statement *before* the while loop that initializes NEXTSYS

Maybe try printing the value of NEXTSYS before the loop and once while into the loop?
--
Jangita | +256 76 91 8383 | Y! & MSN: jangita@yahoo.com
Skype: jangita | GTalk: jangita.nyagudi@gmail.com


Reply to: