This is the mail archive of the gcc@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]

Re: Promoting floats to doubles?


Kean Johnston wrote:
Is there a way I can instruct GCC to always promote floats?

In K&R C, floats are promoted to double. In ISO C, they are not.


The main difference here is prototypes. If you have an old-style function definition, and there is no prototype in scope, then it will be compiled with floats promoted to double. If you have a function call, and there is no prototype in scope, or this is an unnamed stdarg argument, then a float will be promoted to double.

If there is a prototype, and the prototype specifies float, then the float will not be promoted to double.

It sounds like you have a prototype that disagrees with the function definition, in which case you should fix the prototype.

There are some hooks here, TARGET_PROMOTE_FUNCTION_ARGS, TARGET_PROMOTE_PROTOTYPES, TARGET_PROMOTE_FUNCTION_RETURN, but they are really only useful for promoting char/short/int types. They won't work for promoting float to double.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



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