I'm writing a program which converts CIL bytecode to C source code for machine consumption. I was concerned about inaccuracy in floating-point constants due to conversion to and from decimal. After doing some research, I discovered that C (but not C++) is supposed to be able to accept a hexadecimal notation for floating-point constants.
I decided to try it out, but MS VC9 gives me errors no matter what I try. Here is what I'm trying:
// Switches: /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /FD /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TC
#include <tchar.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
double d = 0x1.0p+1; // error C2059
//double d = 0x1p+1; // doesn't work either
//double d = 0x1p1; // doesn't work either
//double d = 0x1.0p1; // doesn't work either
printf( "%f\n", d );
return 0;
}
I expected this to print out 2, from 1x2^1, but instead it gives me this compiler error:
error C2059: syntax error : 'bad suffix on number'
I realize C++ doesn't support this syntax (or so I've read,) but notice this is compiled with /TC
so it should be straight C, and I used a *.c
filename for good measure also.
Am I doing something wrong here, or is VC9 just not standards compliant?