Help me out on Float Double Parameters
John Gilmore
gnu at hoptoad.uucp
Wed Apr 9 19:53:07 AEST 1986
In article <3439 at sun.uucp>, guy at sun.uucp (Guy Harris) writes:
> 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.
I think the above applies to CALLS of the function, not DEFINITIONS of the
function. But let me see if I understand how this works. If I write:
foo(float x) {...} /* DEFINE */
then (if this is legal, which I don't know) it expects it as float.
(Of course, any time the DEFINITION expects float, there had better
be a DECLARATION in the callers' routines that matches.)
foo(x) float x; {...} /* DEFINE */
I presume for compatability it must expect double.
foo(float x); /* DECLARE */
foo(x) float x; {...} /* DEFINE */
Now maybe it can expect float? Suppose the declaration and the
definition are separated by a few pages, or the declaration is in
a header file -- how will you know what the routine expects?
foo(float x) float x; {...} /* DEFINE */
Is this legal? Does it take float or double?
Is the same true if you declare an argument char or short? Does it
avoid the widening to int on the stack?
I can see that no matter what the answers to the above questions, the C
standardization process is not making C any simpler to use. Sigh.
Feeping creatureism is leaving its trail of turds.
--
John Gilmore {sun,ptsfa,lll-crg,ihnp4}!hoptoad!gnu jgilmore at lll-crg.arpa
Post no bills.
More information about the Comp.lang.c
mailing list