Forward declaration (was Re: Novice question.)

loki mwjester at wsuiar.uucp
Fri Nov 16 06:04:31 AEST 1990


In article <1990Nov14.143802.23021 at noose.ecn.purdue.edu>,
 longshot at monkey.ecn.purdue.edu (The Knight Guard) writes:
>>	"extern" means that the variable is global, and was declared in a
>>separate .c file.  If your program occupies only 1 file, you will never
>>use this.
>>
>>John Gordon
> 
> 	Not true here...  Our cc seems to require that all functions/procedures
>   be defined before the main block.  The way around this is to extern all 
>   functions before main...  Dunno if this is just our compiler, anyone else
>   seen this?  Any ideas of why?

I'm not sure what compiler/environment you're using, but you will often find
that a function used in main() is assumed to return type int unless the 
compiler has reason to believe otherwise.  When the function appears later
in the text and returns a different type, the compiler accuses you of
redefining it.

You should be able to work around this by defining the return type expected
within main(), e.g.

	main()
	{
		int a,b;
		double bogus();
		.
		.
		.
	}

The above just lets the compiler know about bogus()'s return type, and you
needn't specify the parameters to the function, just its type.

Hope this helps.

Max J.



More information about the Comp.lang.c mailing list