www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/11/10/19:31:39

Date: Thu, 11 Nov 93 09:11:16 JST
From: Stephen Turnbull <turnbull AT shako DOT sk DOT tsukuba DOT ac DOT jp>
To: wonko AT fubar DOT bk DOT psu DOT edu
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: re: second of two questions

According to Brian Hechinger <wonko AT fubar DOT bk DOT psu DOT edu>

   second guestion.  when writing c++ code, i have to make main an int not
   a void and return needs a value, what is the reason behind this??

   from what i remember about my c++ class i had god knows how long ago
   we could do this:

   void main()
   {
      program lines
      return;
   }

I imagine that the powers that be decided that it was a bad idea to
allow the program to exit without specifying a return code.  Good
style in the original C++ required an `exit(exit_code)' statement on
every possible execution path.  (That may not have been taught in your
C++ class....)

   but when i tried this with djgpp it forced me to do it this way:

   int main()
   {
      program lines
      return 0;
   }

My program template puts `return FALL_THROUGH__ERROR_RETURN_CODE;' at
the bottom of main().  This ensures that if I didn't trap *all* of the
execution paths that an error is signalled.  This is useful when
working with a filter-style program that avoids gratuitous output to
stdout (note that since you missed this thread, you *didn't* put an
error message on it!)  At least you know that you fell through to the
bottom of main.
    I once had a program that decreased its allocated size by a
block (in both source and executable) when I deleted this statement
after debugging.  I wonder what the odds against that are?  :-)

    --Steve

- Raw text -


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