prototype my function, please

Wayne Throop throopw at sheol.UUCP
Tue May 29 09:43:39 AEST 1990


> I get the bad feeling that I am going to get flamed for this...
No, but my reply may revive a long-forgotten flame-war...

>  But I can see no reason why my Turbo C compiler does not like 
> the way I prototype the following program.
> [..paraphrasing..
> void x(float);
> void main(){x(1.0);}
> void x(v) float v; {}   ..]

Many people pointed out quite correctly that the forward declaration
of the function disagrees with its definition later, because in old-style
function definitions, float is promoted to double.  The simplest way to
fix it is to change the third line to something like

> void x(float v){}

However, nobody seems to have noticed the other type gaffe, namely

> void main(){...}

The function named "main" in C environments is not how, and has never been,
of type (void ()).  At the very least, it should be declared as returning
an (int), and best of all is to declare it completely, with argc and argv and
the whole nine yards.

Remember: there is a contract with that fragment of your C environment
that invokes the main routine (often called "crt0" for reasons unknown to me)
which says that the routine will return an integer value.  It is unwise
to lie to the compiler in this way.
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw at rti.rti.org



More information about the Comp.lang.c mailing list