Path: utzoo!attcan!telly!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Newsgroups: comp.lang.c Subject: Re: prototype my function, please Message-ID: <1990Jun2.091606.9125@druid.uucp> Date: 2 Jun 90 09:16:06 GMT References: <1231@wet.UUCP> <0705@sheol.UUCP> <1990May31.135230.242@druid.uucp> <236@taumet.COM> Reply-To: darcy@druid.UUCP (D'Arcy J.M. Cain) Organization: D'Arcy Cain Consulting, West Hill, Ontario Lines: 39 In article <236@taumet.COM> steve@taumet.UUCP (Stephen Clamage) writes: >In article <1990May31.135230.242@druid.uucp> darcy@druid.UUCP (D'Arcy J.M. Cain) writes: >>So can anyone summarize the ANSI compilers (or K&R1 compilers for that >>matter) for which decalaring main to return void causes a problem? > >As to "lying to the compiler" when you terminate via exit(), the >standard says: > "A return from the initial call to the _main_ function function > is equivalent to calling the _exit_ function with the value returned > by the _main_ function as its argument." >So the compiler is not allowed to be upset when exit() does not return. > I wasn't worried about exit() not returning. Rather the fact that there is no need to return from main if exit() is used to leave a program. In the following program: #include int main(int argc, char **argv) { printf("%s has %d arguments\n", *argv, argc); exit(0); } The compiler will give a warning that a function (main) which should return an int does not return anything. If, like me, you prefer super quiet compiles you must add a return(0) statement. You now have added code (which won't be optimised out) which has no other purpose than to shut the compiler up. I will do that when necessary but try to avoid it whenever possible. Note that I realize that the exit above can be replaced by a return but this is a trivial example. In practice the exit may not even be in the main routine. -- D'Arcy J.M. Cain (darcy@druid) | Government: D'Arcy Cain Consulting | Organized crime with an attitude West Hill, Ontario, Canada | (416) 281-6094 |