Float Double Parameters

M.J.Shannon mjs at sfsup.UUCP
Wed Apr 2 14:54:30 AEST 1986


> In article <5216 at alice.uUCp> ark at alice.UucP (Andrew Koenig) writes:
> >>X3J11 says "arguments that have type float are promoted to double". Too bad.
> >
> >Ansi C also lets you declare types of formal parameters to externals:
> >
> >	extern float f(float x);
> >in which case:
> >	f(1);		/* 1 is converted to float */
> >	f(1.0);		/* 1.0 is converted to float */
> >
> >are both OK.
> 
> OK, but doesn't "extern float f(float x)" really mean
> "extern float f( double x )"?

No.  It really means what it says!

> 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.

Wrong.  The actual parameters (1 and 1.0) above are converted to float.

> If the above *is* correct, then apparently I can pass a float to a function
> ( provided it is not defined in the current file (!?!?!?!) ) but it is *not*
> possible to write a function that accepts a float as a parameter.

The following function accepts a float as a parameter:

void f(float x)
{
	return;
}

> C is strange, but not that strange - I suspect Mr. Koenig has read something
> into the standard that is not there.  If anyone has reliable information
> to the contrary, let us know...

Please read the latest (or any recent) draft from ANSI.  Please do not
speculate on subjects you don't know anything about.  Ask questions, but
please don't advance your speculations as facts.

> "If you aren't making any mistakes, you aren't doing anything".

You are doing *something*.

> Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg
-- 
	Marty Shannon
UUCP:	ihnp4!attunix!mjs
Phone:	+1 (201) 522 6063

Disclaimer: I speak for no one.

"If I never loved, I never would have cried." -- Simon & Garfunkel



More information about the Comp.lang.c mailing list