prototype my function, please...

Andrew Koenig ark at alice.UUCP
Tue May 22 07:43:10 AEST 1990


In article <1231 at wet.UUCP>, noah at wet.UUCP (Noah Spurrier) writes:

> I get the bad feeling that I am going to get flamed for this... But I can
> see no reason why my Turbo C compiler does not like the way I prototype
> the following program.

> /* Protoypte */
> void x (float);

	/* ... */

> void x (y)
> float y;
> {
>  printf ("%f",y);
> }

You should do it this way:

	void x(float y)
	{
		printf("%f",y);
	}

The point is that old-style parameter declarations are decidedly
not equivalent to new-style declarations.  For compatibility reasons,
it must be legal to define

	void x(y)
		float y;
	{
		/* ... */
	}

and call it from a separately compiled module without any declaration
there at all.  That means it must be capable of accepting a double
parameter.  Thus, in effect, this least example is equivalent to:

	void x(double dummy)
	{
		float y = dummy;
		/* ... */
	}

In other words, if you want to use ANSI-style function prototypes,
you must use them consistently.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list