A
arindam.mukerjee
I was running code like:
#include <stdio.h>
int main()
{
printf("%f\n", 9/5);
return 0;
}
and saw that the value being printed was -0.000000 (gnu) or 0.000000
(msvc6). I was expecting 2.000000.
Next I tried this:
#include <stdio.h>
int main()
{
int x = 27837;
/**1**/ double f = x;
printf("%f\n", x);
return 0;
}
and the value now printed was -1.98376 (essentially garbage, gnu) and
0.000000 (msvc6). If I comment out the line I have marked with /** 1
**/, then it goes back to printing -0.000000 (gnu) or 0.000000 (msvc6).
Does the declaration of a double cause linking with some floating point
libraries which causes the difference on GNU?
Why does not an automatic cast happen?
I then tried the following two:
#include <stdio.h>
int main()
{
int x = 27837;
double f = x;
printf("%f\n", f);
return 0;
}
This works fine - we get 27837.000000 as expected.
And this:
#include <stdio.h>
int main()
{
int x = 27837;
void * v = &x;
double *f = v;
printf("%f\n", *f);
return 0;
}
and this once again gives output, which on gnu has an uncanny
similarity to the garbage it printed before just when I uncommented the
"double f = x" line.
What's going on?
-- Arindam
#include <stdio.h>
int main()
{
printf("%f\n", 9/5);
return 0;
}
and saw that the value being printed was -0.000000 (gnu) or 0.000000
(msvc6). I was expecting 2.000000.
Next I tried this:
#include <stdio.h>
int main()
{
int x = 27837;
/**1**/ double f = x;
printf("%f\n", x);
return 0;
}
and the value now printed was -1.98376 (essentially garbage, gnu) and
0.000000 (msvc6). If I comment out the line I have marked with /** 1
**/, then it goes back to printing -0.000000 (gnu) or 0.000000 (msvc6).
Does the declaration of a double cause linking with some floating point
libraries which causes the difference on GNU?
Why does not an automatic cast happen?
I then tried the following two:
#include <stdio.h>
int main()
{
int x = 27837;
double f = x;
printf("%f\n", f);
return 0;
}
This works fine - we get 27837.000000 as expected.
And this:
#include <stdio.h>
int main()
{
int x = 27837;
void * v = &x;
double *f = v;
printf("%f\n", *f);
return 0;
}
and this once again gives output, which on gnu has an uncanny
similarity to the garbage it printed before just when I uncommented the
"double f = x" line.
What's going on?
-- Arindam