×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
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 ...
}
As an Amazon Associate we earn from qualifying purchases.