delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/03/13:36:13

From: sacleary AT mtu DOT edu (Stephen A. Cleary)
Newsgroups: comp.os.msdos.djgpp
Subject: void main ?
Date: 3 Jul 1997 12:21:30 -0400
Organization: Michigan Technological University
Lines: 18
Message-ID: <5pgjia$5v3@fishlab15.fsh.mtu.edu>
NNTP-Posting-User: sacleary AT fishlab15 DOT fsh DOT mtu DOT edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

The reason that void main(...) is considered unacceptable is because of the way main (meaning your function) is loaded and called on various platforms.  While it is true that I have never had a problem with void main(...) on any of the platforms I work on, the standard does not provide any guarantee that this is true on other platforms.

Think about it a minute... if your compiler/OS wasn't too smart, when the OS loads up your program, it will assume that it returns int, so when your program ends, the OS would try to pop an extra int off the stack.  This is why all C (and C++) programs are officially integer-returning.

At least, I think so.

Note also that main can be either:
int main(void);
int main(int argc, char *argv[]);

but not:
int main(int argc, char *argv[], char *env[]);

This last one used to be commonly used to get at the environment variables, but is illegal in ISO/ANSI C.


	-Steve
	 (sacleary AT mtu DOT edu)

- Raw text -


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