[Cfp-interest 1688] AI about no prototype, varargs prototype, and default promotion

Jim Thomas jaswthomas at sbcglobal.net
Wed Jul 8 15:44:23 PDT 2020


Action item:
> AI: Jim+Fred: no prototype vs varargs prototype.  Find where in C where float is promoted to double.

This action item follows up on David Olsen’s suggestion to promote narrow binary interchange types to double. See

[Cfp-interest 1599] promotion for binary interchange types  <https://mailman.oakapple.net/pipermail/cfp-interest/2020-June/001613.html>  Jim Thomas
[Cfp-interest 1634] Re: promotion for binary interchange types  <https://mailman.oakapple.net/pipermail/cfp-interest/2020-June/001648.html>  Jim Thomas

Relevant parts of C:

=========================
6.5.2.2 Function calls

[6] If the expression that denotes the called function has a type that does not include a prototype, the integer promotions are performed on each argument, and arguments that have type float are promoted to double. These are called the default argument promotions. …

[7] … The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter. The default argument promotions are performed on trailing arguments.


7.16.1.1 The va_arg macro

[2] … If there is no actual next argument, or if type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined, except for the following cases:
=========================

This says that the default argument promotions are performed on arguments to functions without prototypes and on arguments matching ellipsis notation for functions without prototypes, and the va-arg macro works with the default argument promotions. So if we expand the definition of default argument promotions to promote _Float16, _Float32, _Float64 to double then those promotions automatically apply for no-prototypes, ellipsis notation, and va_args.

Further discussion …

What would be the rationale for promoting _Float16, _Float32, _Float64 to double?

It allows using these types as printf arguments.

It follows the general approach suggested by the promotion of float to double.

It matches what David Olsen is proposing to C++. (Though he’s willing to change his proposal on this point if we specify something else.)


- Jim Thomas, with Fred Tydeman

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20200708/388fba3b/attachment-0001.htm>


More information about the Cfp-interest mailing list