using floats in functional prototypes

Geoff Rimmer geoff at warwick.UUCP
Mon Jan 23 17:59:25 AEST 1989


In article <1989Jan18.092522.14499 at gpu.utcs.toronto.edu> romwa at gpu.utcs.toronto.edu (Royal Ontario Museum) writes:

>---------tst.c-------------------------------------------------
>	#include <stdio.h>
>
>	void afunc( float );
>
>	void main( void )
>	{
>  		float flt_val = 6.5;
>
>  		afunc( flt_val );
>	}
>
>
>---------tst2.c------------------------------------------------
>	#include <stdio.h>
>
>	void afunc( float );
>
>	void afunc( flt_val )
>		float flt_val;
>
>	{
>  		int i;
>  		i = 3;
>	}

The problem is that you are using the old way of defining the function
afunc().  You should the new method:

	void afunc(float flt_val)
	{
	...
	}

BTW, rather than have to repeat the function prototype in both source
files, put it once in tst2.h, and get both tst.c and tst2.c to
#include "tst2.h".  Finally, if you want to do a function prototype
for a function with no arguments (e.g. main() in your example), the
PROTOTYPE should have 'void' between the parentheses, but the
DEFINITION shouldn't:

e.g., rewriting your tst.c

	#include <stdio.h>

	void afunc(float);
	void main(void); /* prototype  */
	void main()      /* definition */
	{
  		float flt_val = 6.5;

  		afunc( flt_val );
	}

	------------------------------------------------------------
	Geoff Rimmer, Computer Science, Warwick University, England.
			geoff at uk.ac.warwick.emerald

	"Why don't we go out for just ONE drink?"
	"No.  Because you know what would happen then, don't you?"
	"Lager Frenzie!"
	"And one thing you can't do after Lager Frenzie, is get up
	at 4.30 in the morning."
	"We could exercise restraint."
	"Yes, but then again in the real world, perhaps we couldn't!"

		- Filthy Rich and Catflap, 1986.
	------------------------------------------------------------



More information about the Comp.lang.c mailing list