This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Trouble with floating point constants in printf and different versions of gcc


Hi,

I have noticed a strange behaviour in different versions of gcc and don't know if it is correct according to the C99 standard. Here is a test case:

#include <stdio.h>

int
main(int argc, char *argv[])
{
	printf(" 268517138.f = %f\n", 268517138.f);
	
	return 0;
}

gcc 4.5 and 4.6 produce different output when compiled with -std=c99 than gcc 4.2 and 4.4.

/tmp % gcc -v
Using built-in specs.
Target: i386-undermydesk-freebsd
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719  [FreeBSD]

/tmp % gcc44 -v
Using built-in specs.
Target: i386-portbld-freebsd8.1
Configured with: ./../gcc-4.4-20101221/configure --disable-nls --libdir=/usr/local/lib/gcc44 --libexecdir=/usr/local/libexec/gcc44 --program-suffix=44 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc44/include/c++/ --with-ld=/usr/local/bin/ld --with-libiconv-prefix=/usr/local --with-system-zlib --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc44 --build=i386-portbld-freebsd8.1
Thread model: posix
gcc version 4.4.6 20101221 (prerelease) (GCC) 

/tmp % gcc45 -v
Using built-in specs.
COLLECT_GCC=gcc45
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc45/gcc/i386-portbld-freebsd8.2/4.5.3/lto-wrapper
Target: i386-portbld-freebsd8.2
Configured with: ./../gcc-4.5-20110310/configure --enable-lto=yes --with-libelf=/usr/local --disable-nls --libdir=/usr/local/lib/gcc45 --libexecdir=/usr/local/libexec/gcc45 --program-suffix=45 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc45/include/c++/ --with-ld=/usr/local/bin/ld --with-libiconv-prefix=/usr/local --with-system-zlib --disable-rpath --enable-libgcj --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc45 --build=i386-portbld-freebsd8.2
Thread model: posix
gcc version 4.5.3 20110310 (prerelease) (GCC) 

/tmp % gcc46 -v
Using built-in specs.
COLLECT_GCC=gcc46
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc46/gcc/i386-portbld-freebsd8.1/4.6.0/lto-wrapper
Target: i386-portbld-freebsd8.1
Configured with: ./../gcc-4.6-20110101/configure --enable-lto=no --disable-nls --libdir=/usr/local/lib/gcc46 --libexecdir=/usr/local/libexec/gcc46 --program-suffix=46 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc46/include/c++/ --with-ld=/usr/local/bin/ld --with-libiconv-prefix=/usr/local --with-system-zlib --disable-rpath --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc46 --build=i386-portbld-freebsd8.1
Thread model: posix
gcc version 4.6.0 20110101 (experimental) (GCC) 

/tmp % gcc 1.c
/tmp % ./a.out
 268517138.f = 268517152.000000
/tmp % gcc44 1.c
/tmp % ./a.out
 268517138.f = 268517152.000000
/tmp % gcc45 1.c
/tmp % ./a.out
 268517138.f = 268517152.000000
/tmp % gcc46 1.c
/usr/local/bin/ld: error in /usr/local/lib/gcc46/gcc/i386-portbld-freebsd8.1/4.6.0/crtend.o(.eh_frame); no .eh_frame_hdr table will be created.
/tmp % ./a.out
 268517138.f = 268517152.000000

/tmp % gcc -std=c99 1.c
/tmp % ./a.out
 268517138.f = 268517152.000000
/tmp % gcc44 -std=c99 1.c
/tmp % ./a.out
 268517138.f = 268517152.000000
/tmp % gcc45 -std=c99 1.c
/tmp % ./a.out
 268517138.f = 268517138.000000
/tmp % gcc46 -std=c99 1.c
/usr/local/bin/ld: error in /usr/local/lib/gcc46/gcc/i386-portbld-freebsd8.1/4.6.0/crtend.o(.eh_frame); no .eh_frame_hdr table will be created.
/tmp % ./a.out
 268517138.f = 268517138.000000

Note: I am not subscribed to the list, please CC me when replying.

Thank you,
Momchil


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]