Yes. There is no other code in the program that touches this variable.
It appears that the original programmer is using it to do infinite loop.
As you and others have mentioned, it's a strange way to do infinite
loop.
I changed while (num=num) to while (num==num) and the program starts to
work again.
(Note: I think the original programmer miss type == to =. He was a
system programmer and has done all kind of stuffs with different type of
languages. Maybe he had RPG in mind when programming in C. :))
-----Original Message-----
From: c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx
[
mailto:c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx] On
Behalf Of Scott Klement
Sent: Monday, April 16, 2007 12:11 PM
To: C programming iSeries / AS400
Subject: Re: [C400-L] upgrade from V5R2 to V5R3.
Hi Lim,
Is this the actual code? I.e. did you really have a variable named
"num" that was uninitialized and assigned to itself??
Or is this "simplified" code to make it easier for us to understand?
I'm a little concerned that you might've changed the logic a little bit
when you "simplified" it.
int num;
while (num=num) {
. . .
. . .
}
This code says the following:
a) Define an integer named "num".
b) Note: "num" has not been set to anything. Unlike RPG, C does not
automatically set variables to zero when they're created, so "num" could
potentially have ANY value when this program starts. It might be zero,
it might not. Are you sure that in the real program, nothing ever set
the value of "num"?
c) Assign the value of num to itself. This is where I'm wondering if
you changed the logic of the code a bit. It makes no sense to assign a
variable to itself.
d) loop while the value that was assigned in step C isn't 0.
Are you sure your code wasn't more like this:
int x,y;
... other code is here. it sets the value of x...
while (y=x) {
. . .
}
That would make far more sense.
At any rate, I can't imagine that this is really a release upgrade
thing. The behavior of a while loop with assignment, like the one you
posted, has been well-defined since the 1970's. If V5R2 handled it
wrong, there'd be a lot of software that didn't work.
Also, I really can't see why you'd want to do this:
int num;
while (num==num) {
}
That would be silly. Why define a variable named "num" and then check
it against itself in a loop? It'd always be equal to itself! Seems a
little weird to do something like that. If you really want an infinite
loop, then code it a little more clearly.
while (1) {
... do indefinitely ...
}
or
for (;;) {
... do indefinitely ...
}
--
This is the C programming iSeries / AS400 (C400-L) mailing list To post
a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or
change list options,
visit:
http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/c400-l.
As an Amazon Associate we earn from qualifying purchases.