void main (was: Turbo C atexit function.)

Karl Heuer karl at haddock.ima.isc.com
Thu Jun 22 03:52:27 AEST 1989


In article <22420 at iuvax.cs.indiana.edu> bobmon at 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 at 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.



More information about the Comp.lang.c mailing list