pi problem with 5.0b
2 messages in this thread
Mike,
I have discovered the problem with the pi problem. It is not a code
generation problem. Rather, the program assumes that the following
construct will initialize both a and b to 0:
int a, b = 0;
The compiler, however, only sets b to zero while a has a garbage value.
This garbage value was upsetting the result. It turns out, after debugging
with sdb, that the 16 bit version did the same thing only the garbage value
was much smaller and so the final answer was much closer. Changing the
lines in math.c to the form:
int a = 0, b = 0;
solved the problem. Is the first form supposed to work? The first edition
if K & R suggests not, but then why is Microsoft using it? Is it perhaps a
Unix standard and not ANSI? Just curious…
John
John,
Each auto variable you wish initialized must be separately
initialized.
int a,b=0; /* will only initialize b */
int a = 0, b = 0; /* will initialize both */
int a = 0, b = a; /* will likewise initialize both */
By definition, uninitialized auto variable's contents will be
"undetermined" or garbage.
This is both K&R (v1 and v2) and ANSI.
Don