Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!decwrl!decvax!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: void main (was: Turbo C atexit function.) Message-ID: <13789@haddock.ima.isc.com> Date: 21 Jun 89 17:52:27 GMT References: <166@enuxha.eas.asu.edu> <22420@iuvax.cs.indiana.edu> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 35 In article <22420@iuvax.cs.indiana.edu> bobmon@iuvax.cs.indiana.edu (RAMontante) writes: >Doug Gwyn's comment about main()'s return value can also be finessed by >declaring it as void main(void) > >[I don't know if this is legitimate, but it silences the warning messages.] Firstly, if you really are falling off the bottom of |main()|, then this is worse than useless; it's silencing a warning about a real bug. Secondly, even if you're not falling off the bottom (e.g., if you terminate with an explicit |exit()|), it is (alas) not sanctioned by the pANS. The only valid types for |main()| are |int main(void)| or |int main(int, char **)|.$ #pragma OPINION ON Given that |main()| is already a special case in that it has two valid types, I think that it should also have been allowed to return either |int| or |void| (where |void| would be used in the same sense as with |exit()| and |abort()|, i.e. "function does not return" rather than "function returns no value"). That way, those of use who prefer% |exit()| over |return| could use the |void| declaration, avoiding the potential warning message "|int| function returns no value", which should be (but isn't) a standard lint warning, now that the existence of |void| has made pseudo-void& functions obsolete. #pragma OPINION OFF Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint ________ $ Although |argv| can be *written* with array brackets, the resulting type of |main| will still be |int (int, char **)|. % Discussion about whether |exit| or |return| is "better" is no more welcome than discussion about indentation styles. & pseudo-void functions are those that return no value, yet are not declared |void|, often due to having been written before |void| was common usage. See K&R1 for examples.