Path: utzoo!attcan!uunet!cs.utexas.edu!rutgers!mcnc!rti!sheol!throopw From: throopw@sheol.UUCP (Wayne Throop) Newsgroups: comp.lang.c Subject: Re: prototype my function, please Summary: a secondary error Message-ID: <0705@sheol.UUCP> Date: 28 May 90 23:43:39 GMT References: <1231@wet.UUCP> Lines: 33 > 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 !mcnc!rti!sheol!throopw or sheol!throopw@rti.rti.org