A
ais523
I have some code, which I know will not work (I haven't included
<math.h>, so sqrt will be assumed to return an int). What I want to
know is, is an ANSI-compliant implementation required to produce an
executable as output (even if the actual output is undefined)?
#include <stdio.h>
/*#include <math.h>*/
int main()
{
float a=36.0;
a=sqrt(a);
printf("%f; %d; %d; %d",a,sizeof(int),sizeof(float),sizeof(double));
getchar();
return 0;
}
(I use the printf line to see how various implementations treat the
code. I have compiled this code under 4 different implementations; in
each case, the code runs, but only under gcc has it produced the answer
6.0. In most cases, the compiler interprets the bit-pattern of the
double 6.0 as an int, converts that to a float, and then prints it.)
Thanks in advance.
<math.h>, so sqrt will be assumed to return an int). What I want to
know is, is an ANSI-compliant implementation required to produce an
executable as output (even if the actual output is undefined)?
#include <stdio.h>
/*#include <math.h>*/
int main()
{
float a=36.0;
a=sqrt(a);
printf("%f; %d; %d; %d",a,sizeof(int),sizeof(float),sizeof(double));
getchar();
return 0;
}
(I use the printf line to see how various implementations treat the
code. I have compiled this code under 4 different implementations; in
each case, the code runs, but only under gcc has it produced the answer
6.0. In most cases, the compiler interprets the bit-pattern of the
double 6.0 as an int, converts that to a float, and then prints it.)
Thanks in advance.