From: Phil Galbiati Newsgroups: comp.os.msdos.djgpp Subject: Re: void main ? Date: Wed, 9 Jul 1997 03:34:21 -0700 Organization: Oregon Graduate Institute - Computer Science & Engineering Lines: 107 Message-ID: References: <33BBABD2 DOT 3249 AT cornell DOT edu> <33C0F3B8 DOT 75F0 AT cornell DOT edu> Reply-To: Phil Galbiati NNTP-Posting-Host: blue.cse.ogi.edu Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <33C0F3B8.75F0@cornell.edu> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Thu, 3 Jul 1997, Giovanni Resta wrote: > > Could someone provide a simple example of a correct program that > goes wrong with "void main(int argc..." ? I'll bet you didn't expect the ANSI Inquisition (after all, NOBODY EXPECTS THE ANSI INQUISITION!!!!!!) On Mon, 7 Jul 1997, Brother Aldrich, Chief Inquisitor and Defender of the Faith wrote: > > void main is a silly violation of ANSI, because it's just as easy to > declare it the right way. Hmmmmm.... quite the religious statement. You seem to forget that there is *nothing* that requires a program to adhere to the ANSI standard. As such, void main() *might* be correct. It depends only on how the program was specified. On Sat, 5 Jul 1997, John M. Aldrich wrote: > > Embedded software is a special case of C/C++ and may not have any > applicability to the general standard. The Inquisitor preacheth HERESY!!!!! Where in the standard is embedded software exempted? Furthermore, since there are far more embedded processors than "general purpose" computers (there are probably two dozen embedded processors in the average American household) embedded software is the *common* case. On Sat, 5 Jul 1997, A. Sinan Unur wrote: > > please read the C faq and the references contained there: The C FAQ is **NOT** an interchangeable substitute for the ANSI standard. It was written by one person with roughly ten years of software engineering / programming experience, and represents only his *opinion*. While most of the contents of the C FAQ are in general good software practices, there are many points which are quite open to debate. Which brings us back to the original question: On Thu, 3 Jul 1997, Giovanni Resta wrote: > > Could someone provide a simple example of a correct program that > goes wrong with "void main(int argc..." ? If a program is specified in such a way that requires it to: 1) comply with the ANSI standard 2) return a specified exit status, or 3) run on under an unspecified operating system then it is not a correct program if main is declared as returning void. If the program is specified such that it need not comply with ANSI, only runs under an operating system which is known to execute void main() programs without choking, and has an unspecified exit status, then void main() is correct in the sense that the program conforms to its specification. For example, a program which is specified like this: 1) must print "Hello, World!" followed by a CR to stdout, and then exit 2) must run under MS-DOS 6.0 3) must be compilable using DJGPP v2.01 may be correctly implemented like this: #include void main () { printf ("Hello, World!\n"); } However, in this case, #include #include int main () { printf ("Hello, World!\n"); return (EXIT_SUCCESS); } is also correct. I am assuming in the first example that the statement in an earlier post that DOS will not choke, is true. The decision to comply with ANSI is usually, but not always, a no-brainer (at least for new code running on most general purpose platforms), since the cost of compliance is relatively small, and the benefits can be enourmous if the program ever is ported to a different architecture. For applications involving non-compliant legacy code, or platforms for which the cost of compliance is significant (for example, a processor for which an ANSI compliant compiler is substancially more expensive than a non-compliant one), the decision becomes more difficult. For most, if not all, DJGPP applications, it is my opinion that Brother Aldrich should be as zealous in the application of the Pokey Pillow and the Comfy Chair to those whose programs fail to return with reasonable exit codes, as he is with those who utter the Blasphemy "void main()". So there. --Phil Galbiati