Problem returning doubles from a function

Andrew Koenig ark at alice.UUCP
Sat Mar 25 09:18:48 AEST 1989


In article <39722 at csvax1.cs.tcd.ie>, omahony at csvax1.cs.tcd.ie (Donal O'Mahony - OMAHONY at cs.tcd.ie) writes:

> #include <stdio.h>
> main()
> {double a,b;
> 
>   a = 1.234;
>   b = store_length(a);
>   printf("b=%f\n",b);
> }

If store_length returns a double, you must declare it as such:

	#include <stdio.h>

	double store_length();

	main()
	{
		double a,b;

		a = 1.234;
		b = store_length(a);
		printf("b=%f\n",b);
	}

In ANSI C, it looks like this:

	
	#include <stdio.h>

	double store_length(double);

	main()
	{
		double a,b;

		a = 1.234;
		b = store_length(a);
		printf("b=%f\n",b);
	}

Failure to declare such functions is a common C pitfall.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list