Float Double Parameters

Guy Harris guy at sun.uucp
Fri Apr 4 04:27:07 AEST 1986


> OK, but doesn't "extern float f(float x)" really mean
> "extern float f( double x )"?  I.e. '1' and '1.0' are passed as doubles to
> f in the above examples. I don't know, but I suppose this feature has been
> added only to allow the compiler to check ( and convert when applicable )
> the parameter types.

Mr. Koenig is correct.  According to the August 11, 1985, X3J11 draft:

	C3.2.2 Function calls

	... Also, *if no function prototype declarator is in scope*, the
	integral promotions are performed and arguments that have type
	"float" are promoted to "double".  ("italics" mine)

	... If a function prototype declarator is in scope, the arguments
	are compared with the formal parameters.  ...The types must be
	such that each formal parameter may be initialized by the
	coresponding argument, and the arguments are converted
	accordingly.

Yes, prototypes were added to allow the compiler to check parameter types
and convert where applicable.  However, this and other changes to the C
language in the draft proposed ANSI standard permit the automatic integral
and "float" to "double" promotions to be gotten rid of in most
circumstances; there was no good reason *not* to eliminate those conversions
in the case of functions with full declarations, and good reason to do so.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.arpa	(yes, really)



More information about the Comp.lang.c mailing list