www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/09/01:29:38

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199607090523.AA195989818@relay1.geis.com>
Date: Tue, 9 Jul 96 05:01:00 UTC 0000
To: csrabak AT dce03 DOT ipt DOT br
Cc: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: main vs void main?

Reply to message 0675956    from CSRABAK AT DCE03 on 07/08/96  6:03PM


>>BTW, just using 'main()' as your definition is not very good either.  While
it
>>is technically correct (an unstated return value defaults to int and an empty
>>argument list defaults to void), you are relying on the _compiler_ to
>               ^^^^^^^^^^^^^^^^Not quite! In ISO (ANSI) for compatibility
>with existing code, it may mean anything from "void" to "any number of
>arguments". In C++ however your observation apply in full. So it is better
>(in ISO/ANSI C) to follow your own advice!

Actually, what you are referring to is not ANSI at all, but rather the
compatibility of nearly all ANSI compilers with the ambiguous function
definition methodology of traditional C.  Under _pure_ ANSI, an empty
argument list indicates a void argument list.  So using 'main()' is only
truly dangerous if you are writing a program which may be compiled
on a traditional compiler.  In that case, however, 'int main( void )' would
fail, because 'void' is not recognized by traditional C.  As long as you
stay within ANSI, empty argument lists are not actually dangerous, just
bad programming.

John

- Raw text -


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