Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.std.c Subject: Re: Must main return a value? Message-ID: <16579@smoke.brl.mil> Date: 28 Jun 91 23:43:39 GMT References: <7830001@hpwrce.HP.COM> <1991Jun28.055840.29919@tkou02.enet.dec.com> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 15 In article <1991Jun28.055840.29919@tkou02.enet.dec.com> diamond@jit533.enet@tkou02.enet.dec.com (Norman Diamond) writes: >It does seem strange that the compiler is required to issue a diagnostic for >a return statement with a value in a void function, but not for the opposite >mistake. That's because a vast amount of existing, correct (as of when it was written) C code is like that. Before there was a "void" type in C, the effect of a void-valued function was achieved by coding a (default) int-valued function and not returning a value. It's easy for an implementation to deal with this common practice (either by not worrying about loading the result register or by building a dummy result value before the function exit code), and as a widespread officially-sanctioned practice (K&R 1st Ed. had examples), there was no good reason to disallow this usage. All that X3J11 had to do along these lines was to note the obvious fact that an attempt to use a value that the program hadn't bothered to set up would be nonsensical.