Created attachment 27227 [details]
the preprocessed file (*.i*) that triggers the bug
Exact version of GCC: That I know that version 4.3, 4.6 and 4.7 has this bug.
System Type: x86_32, i686, 32BITS Intel architecture. It don't occurs in 64 bit intel architectures.
Options given when GCC was configured/build: The error happen when you use -std=gnu99 ¡¡BY DEFAULT :O!! standar or -std=gnu89, but not when you use other standar like -std=c99
The complete command line that triggers the bug: "gcc main.c -o main"
The compiler output (error messages, warnings, etc.): None.
the preprocessed file (*.i*) that triggers the bug, generated by adding -save-temps to the complete compilation command, or, in the case of a bug report for the GNAT front end, a complete set of source files (see below): As attachment
Thank's I love GNU & your work a million of thanks.
char *cadena = "-25.9";
//USING A TEMP VARIABLE
double d = atof(cadena) * 10;
short s1 = (short) d;
printf("%d\n",s1); //I GET -259
//WITHOUT A TEMP VARIABLE
short s2 = atof(cadena) * 10;
printf("%d\n",s2); //I GET -258????????????????????????????? WTF?
I use one architecture of 64 bits OR
I use the standard -std=99 OR
I use a temporal double variable OR
I compile other compiler that is not GCC
I don't get this error.
Ok I acept the response "This is the result of rounding".
All we know that the nearest representable number for a double (-259.0000) in a short is (-258). I answering me if you really take a look to the code of main.
double a = 0.5;
double b = 0.01;
std::cout << (int)(a / b) << std::endl;
// No error.
double c = a/b;
std::cout << (int)c << std::endl;
* I compile with other...
Sory, about my last sarcastic expresions, and my bad english.
I take a look to the paper when I have time.
Thanks for improve the GNU compiler GCC.
*** This bug has been marked as a duplicate of bug 323 ***