delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/17/00:54:56

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199607170448.AA212968903@relay1.geis.com>
Date: Wed, 17 Jul 96 04:34:00 UTC 0000
To: nchudnof AT mbhs DOT edu
Cc: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: int main()

Reply to message 5546954    from NCHUDNOF AT BINX on 07/16/96  9:30AM


>A while ago, there was a conversation about 'void main()' vs. 'int main()'
>and I wondered if:
>
>void main()
>{
>   exit(1);
>}
>
>Is the same as
>
>int main()
>{
>   return(1);
>}

You are essentially correct in that those two pieces of code would have
the same effect on the operating system.  However, if a program were
to perform recursive calls to main(), the former definition would not work.
Instead of returning, it would terminate the program.

I argue for the correct definition not out of some perverse stubbornness,
but because doing it any other way can get you into trouble if you make
it a habit.  And I should know as well as anybody the danger of getting into
bad programming habits!  :)

John

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019