[Coco] Preparing for a job which requires knowledge of C

Neil Morrison neilsmorr at hotpop.com
Sat Apr 15 15:10:33 EDT 2006


----- Original Message ----- 
From: "Tony C" <cappy2112 at gmail.com>

> One question stands out on the list, that I haven't been able to find a
solution on
(most of the others I've been able to come up with reasonable answers,
considering I haven't used the language in over 8 years)

> What is the difference between main() in a C program, and main() in a C++
program?

Not sure there is any. This is from Microsoft:

main: Program Startup

A special function called main is the starting point of execution for all C 
and C++ programs. If you are writing code that adheres to the Unicode 
programming model, you can use the wide-character version of main, wmain.
The main function is not predefined by the compiler; rather, it must be 
supplied in the program text.
The declaration syntax for main is:

int main( );

or, optionally:

int main( int argc[ , char *argv[ ] [, char *envp[ ] ] ] );

Microsoft Specific
The declaration syntax for wmain is as follows:

int wmain( );

or, optionally:

int wmain( int argc[ , wchar_t *argv[ ] [, wchar_t *envp[ ] ] ] );

The types for argc and argv are defined by the language. The names argc, 
argv, and envp are traditional, but are not required by the compiler. See 
Argument Definitions for more information and for an example.
Alternatively, the main and wmain functions can be declared as returning 
void (no return value). If you declare main or wmain as returning void, you 
cannot return an exit code to the parent process or operating system using a 
return statement; to return an exit code when main or wmain is declared as 
void, you must use the exit function.




More information about the Coco mailing list