This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
help understanding behaviour of unsuffixed float constants
- From: "Regan, Brian (EPC COE)" <brian dot regan at honeywell dot com>
- To: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
- Date: Thu, 22 May 2014 19:16:43 +0000
- Subject: help understanding behaviour of unsuffixed float constants
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=neutral (sender IP is 199.61.26.153) smtp dot mailfrom=brian dot regan at honeywell dot com;
I wonder if someone could help shed light on this for me.
Based on the statement in ISO C spec (ISO 9899:1990) section '6.1.3.1 Floating Constants' statement "An unsuffixed floating constant has type double." it appears to me that the gcc compiler may not be in strict compliance.
--------------sample code start ----------------
/* would have expected conversion from float constant double to variable single */
static float a = 100.0;
int test(void) {
/* force a double and get implicit conversion as expected */
if (a < 200.0E40) {
a = 0.0;
}
/* per ANSI 6.1.3.1 this constant should also be double and implicit conversion is expected */
if (a < 200.0) {
a = 0.0;
}
return 0;
}
__extendsfdf2(){
; /* dummy */
}
__ltdf2(){
; /* dummy */
}
--------------sample code end ----------------
When compiled with '-std=iso9899:199409 -pedantic' I nevertheless see the implicit conversion of 'a' to double only in the case of the first 'if' and not in the second as expected (i.e. 200.0 compiles to float not double as expected by the standard).
Also, the binary value of the constant 100.0 is compiled into 32 bits only.
The GCC version is 4.2.3 and the build was configured as '-target=powerpc-eabispe'. Does this have anything to do with it?
Thanks in advance for any feedback provided.
Brian