Possible negative double to unsigned int conversion error
Eduardo Fernandes
Eduardofer@meta4.com
Fri Sep 27 02:28:00 GMT 2002
Hi there.
The code:
#include <stdio.h>
int main() {
double a = -1;
unsigned int b = 0;
b = (unsigned int) a;
printf("%u %d\n",b,b);
return 0;
}
displays "0 0". It shoud be "4294967295 -1", no isn't?
Many thanks in advance and please find below the info you'll need to check
it out.
Edu.
==================================
> gcc -v -save_temps -o trunc trunc.cpp
Reading specs from
/opt/freeware/gcc-3.1/lib/gcc-lib/powerpc-ibm-aix4.3.3.0/3.1/
specs
gcc: unrecognized option `-save_temps'
Configured with: ../gcc-3.1/configure --prefix=/opt/freeware/gcc-3.1
--exec-pref
ix=/opt/freeware/gcc-3.1 --with-local-prefix=/opt/freeware/gcc-3.1
--enable-shar
ed --enable-threads
Thread model: aix
gcc version 3.1
/opt/freeware/gcc-3.1/lib/gcc-lib/powerpc-ibm-aix4.3.3.0/3.1/cc1plus -v
-D__GNU
C__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -D_IBMR2 -D_POWER -D_AIX
-D_AIX
32 -D_AIX41 -D_AIX43 -D_LONG_LONG -D_IBMR2 -D_POWER -D_AIX -D_AIX32 -D_AIX41
-D_
AIX43 -D_LONG_LONG -Asystem=unix -Asystem=aix -D__NO_INLINE__
-D__STDC_HOSTED__=
1 -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED=1 -D_LARGE_FILE_API
-D_ALL_SOURCE
-D_ARCH_COM trunc.cpp -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS
-D__GXX_ABI_VE
RSION=100 -quiet -dumpbase trunc.cpp -version -o /B/tmp/ccFn1Sya.s
GNU CPP version 3.1 (cpplib)
GNU C++ version 3.1 (powerpc-ibm-aix4.3.3.0)
compiled by GNU C version 3.1.
ignoring nonexistent directory
"/opt/freeware/gcc-3.1/powerpc-ibm-aix4.3.3.0/inc
lude"
ignoring duplicate directory "/opt/freeware/gcc-3.1/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/freeware/gcc-3.1/include/g++-v3
/opt/freeware/gcc-3.1/include/g++-v3/powerpc-ibm-aix4.3.3.0
/opt/freeware/gcc-3.1/include/g++-v3/backward
/opt/freeware/gcc-3.1/include
/opt/freeware/gcc-3.1/lib/gcc-lib/powerpc-ibm-aix4.3.3.0/3.1/include
/usr/include
End of search list.
as -u -mcom -o /B/tmp/ccyh6a6p.o /B/tmp/ccFn1Sya.s
/opt/freeware/gcc-3.1/lib/gcc-lib/powerpc-ibm-aix4.3.3.0/3.1/collect2
-bpT:0x10
000000 -bpD:0x20000000 -btextro -bnodelcsect -o trunc /lib/crt0.o
-L/opt/freewar
e/gcc-3.1/lib/gcc-lib/powerpc-ibm-aix4.3.3.0/3.1
-L/opt/freeware/gcc-3.1/lib/gcc
-lib/powerpc-ibm-aix4.3.3.0/3.1/../../.. /B/tmp/ccyh6a6p.o
/opt/freeware/gcc-3.1
/lib/gcc-lib/powerpc-ibm-aix4.3.3.0/3.1/libgcc.a
/opt/freeware/gcc-3.1/lib/gcc-l
ib/powerpc-ibm-aix4.3.3.0/3.1/libgcc_eh.a -lc
/opt/freeware/gcc-3.1/lib/gcc-lib/
powerpc-ibm-aix4.3.3.0/3.1/libgcc.a
/opt/freeware/gcc-3.1/lib/gcc-lib/powerpc-ib
m-aix4.3.3.0/3.1/libgcc_eh.a
More information about the Gcc-bugs
mailing list