C
Cezary Noweta
Hello,
In Control Panel, Regional Settings, set decimal point to something other then dot
,,.'' (ASCII 0x2E). Let it be comma (ASCII 0x2C) for example. Compile and run the
following code
=== BEGIN of test.c ===
#include <math.h>
#include <stdio.h>
main()
{
#pragma setlocale(".ACP")
printf("ANSI: %3g %3g %3g %3g %7g\n", 0.1, 0.9, 1.1, 1.9, pow(1.999, 10.0));
#pragma setlocale("C")
printf("C: %3g %3g %3g %3g %7g\n", 0.1, 0.9, 1.1, 1.9, pow(1.999, 10.0));
}
=== END of test.c ===
The program gives following result:
ANSI: 0 0 1 1 1
C: 0.1 0.9 1.1 1.9 1018.89
It looks that the lexical analizer internally uses setlocaled version of
atof()/sscanf() to retrieve value of the FP literals. This is strange bug in the
lexer. Such behaviour breaks elementary rules of ISO C standard. Moreover, it does
not generate any warnings/errors regardless of warning level.
Tested on all versions of CL from VS 6.0 SP5 to VS 2005 SP1.
-- best regards
Cezary Noweta
In Control Panel, Regional Settings, set decimal point to something other then dot
,,.'' (ASCII 0x2E). Let it be comma (ASCII 0x2C) for example. Compile and run the
following code
=== BEGIN of test.c ===
#include <math.h>
#include <stdio.h>
main()
{
#pragma setlocale(".ACP")
printf("ANSI: %3g %3g %3g %3g %7g\n", 0.1, 0.9, 1.1, 1.9, pow(1.999, 10.0));
#pragma setlocale("C")
printf("C: %3g %3g %3g %3g %7g\n", 0.1, 0.9, 1.1, 1.9, pow(1.999, 10.0));
}
=== END of test.c ===
The program gives following result:
ANSI: 0 0 1 1 1
C: 0.1 0.9 1.1 1.9 1018.89
It looks that the lexical analizer internally uses setlocaled version of
atof()/sscanf() to retrieve value of the FP literals. This is strange bug in the
lexer. Such behaviour breaks elementary rules of ISO C standard. Moreover, it does
not generate any warnings/errors regardless of warning level.
Tested on all versions of CL from VS 6.0 SP5 to VS 2005 SP1.
-- best regards
Cezary Noweta