Nasty bug

Stephen Clamage steve at taumet.com
Wed Sep 5 01:13:06 AEST 1990


richard at iesd.auc.dk (Richard Flamsholt S0rensen) writes:

>  Nope. ANSI states, that floats remain floats unless the expression
>contains more precise types, that is long double or double, in which
>case the float in converted. Therefore, if the float is the only
>parameter to a function it is *not* converted to a double in the
>expression, regardless of how the function was declared.

This is just wrong.  Section 3.2.1.5 describes the "usual arithmetic
conversions", which are applied to binary operators.  The standard
allows a float to remain a float unless the other operand of the binary
operator is double or long double.  The last sentence of that section
says:
	"The values of floating operands and of the results of floating
	expressions may be represented in greater precision and range
	than that required by the type; the types are not changed thereby."
Thus ANSI allows floats to remain floats in expressions, but also allows
them to be promoted to wider types.

Furthermore, for function arguments, section 3.3.2.2 says:
	"If the expression that denotes the called function has a type
	that does not include a prototype, the integral promotions are
	performed on on each argument and arguments that have type
	float are promoted to double."
It goes on to say:
	"If the expression that denotes the called function has a type
	that includes a prototype, the arguments are implicitly
	converted, as if by assignment, to the types of the
	corresponding parameters."

So given the declarations:
	foo(float);
	doo(double);
	goo();
	float f;
We have the following calls:
	foo(f);	/* f passed as a float * /
	doo(f);	/* f widened to a double */
	goo(f);	/* f widened to a double */
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list