Hi,

While testing my perl scripts I found a strange bug that happens only on
Linux (RH 6.2, 7.0),
See the code below. Before your read the all text, tell me what's the Buffer
value?
"3238200"? The answer is NO! Try this example on your Linux box

SOURCE test.c:
-=-=-=-=
#include <stdio.h>
#include <stdlib.h>

main () {
double Sum, ResultSum;
ResultSum = 10000;
Sum = 323.82;
char *Buffer = new char[255];
sprintf(Buffer, "%d", (long)(Sum * ResultSum));
printf("Buffer = [%s], Sum = %.4f, Sum * Result = %.4f\n", Buffer, Sum, (Sum
* ResultSum));

return 0;
}

RESULTS
-=-=-=-=
now compile on Linux RedHat 6.2 with gcc version egcs-2.91.66 19990314/Linux
(egcs-1.1.2 release)
Output:
$ g++ test.c
$ ./a.out
Buffer = [3238199], Sum = 323.8200, Sum * Result = 3238200.0000
-=-=-=-=

the Buffer value is very strange! I have no ideas how Buffer can be 3238199!
FreeBSD (old 3.x) works well and Buffer=3238200 as it should be, but on
Linux 6.2, 7.0 it is 3238199..

Any ideas?

/Vlad

Reply via email to