Click here to Skip to main content
15,925,528 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: can main() be overloaded?? Pin
David Crow18-Aug-10 9:14
David Crow18-Aug-10 9:14 
AnswerRe: can main() be overloaded?? Pin
Aescleal18-Aug-10 10:00
Aescleal18-Aug-10 10:00 
GeneralRe: can main() be overloaded?? Pin
David Crow18-Aug-10 10:21
David Crow18-Aug-10 10:21 
GeneralRe: can main() be overloaded?? Pin
Aescleal18-Aug-10 10:26
Aescleal18-Aug-10 10:26 
GeneralRe: can main() be overloaded?? Pin
David Crow18-Aug-10 10:35
David Crow18-Aug-10 10:35 
GeneralRe: can main() be overloaded?? Pin
Aescleal18-Aug-10 11:20
Aescleal18-Aug-10 11:20 
GeneralRe: can main() be overloaded?? Pin
CPallini18-Aug-10 22:18
mveCPallini18-Aug-10 22:18 
GeneralRe: can main() be overloaded?? Pin
Emilio Garavaglia18-Aug-10 22:40
Emilio Garavaglia18-Aug-10 22:40 
CPallini wrote:
While I see the point of returning a value of the OS, I personally don't like 'default 0-return value' for code intended to return nothing.


The ponit is that, whatever you like it or not, a process invoked by the OS HAVE TO return an int value back to it. That's how all the kernels are designed.

The OS left the space for an int just before the stack space for main(). Just like C does for whatever function call.

If you declare main as void, you simply tell your program to don't care about the stack under it. That -in fact- doesn't mean "return nothing": it just return to the OS a random value.

The OS is not compiled by you and doesn't link statically your main, so it cannot know what the type it has. It assume it is int. If it's not, the return value will be bogus, not nothing.

2 bugs found.
> recompile ...
65534 bugs found.
D'Oh! | :doh:


GeneralRe: can main() be overloaded?? Pin
CPallini18-Aug-10 22:51
mveCPallini18-Aug-10 22:51 
GeneralRe: can main() be overloaded?? Pin
Aescleal18-Aug-10 23:12
Aescleal18-Aug-10 23:12 
GeneralRe: can main() be overloaded?? Pin
CPallini18-Aug-10 23:40
mveCPallini18-Aug-10 23:40 
GeneralRe: can main() be overloaded?? Pin
DrFrankenstein9019-Aug-10 7:30
DrFrankenstein9019-Aug-10 7:30 
GeneralRe: can main() be overloaded?? Pin
David Crow19-Aug-10 7:50
David Crow19-Aug-10 7:50 
GeneralRe: can main() be overloaded?? Pin
MarvinMartian19-Aug-10 6:37
MarvinMartian19-Aug-10 6:37 
GeneralRe: can main() be overloaded?? Pin
Emilio Garavaglia19-Aug-10 9:33
Emilio Garavaglia19-Aug-10 9:33 
GeneralRe: can main() be overloaded?? Pin
MarvinMartian19-Aug-10 10:50
MarvinMartian19-Aug-10 10:50 
GeneralRe: can main() be overloaded?? Pin
Aescleal20-Aug-10 8:16
Aescleal20-Aug-10 8:16 
GeneralRe: can main() be overloaded?? Pin
MarvinMartian20-Aug-10 8:50
MarvinMartian20-Aug-10 8:50 
AnswerRe: can main() be overloaded?? Pin
AmbiguousName18-Aug-10 21:43
AmbiguousName18-Aug-10 21:43 
GeneralRe: can main() be overloaded?? Pin
Emilio Garavaglia18-Aug-10 22:48
Emilio Garavaglia18-Aug-10 22:48 
GeneralRe: can main() be overloaded?? Pin
Paul Michalik18-Aug-10 22:56
Paul Michalik18-Aug-10 22:56 
GeneralRe: can main() be overloaded?? Pin
Emilio Garavaglia19-Aug-10 9:38
Emilio Garavaglia19-Aug-10 9:38 
GeneralRe: can main() be overloaded?? Pin
Paul Michalik19-Aug-10 22:10
Paul Michalik19-Aug-10 22:10 
GeneralRe: can main() be overloaded?? Pin
Emilio Garavaglia19-Aug-10 22:38
Emilio Garavaglia19-Aug-10 22:38 
AnswerRe: can main() be overloaded?? Pin
englebart19-Aug-10 3:14
professionalenglebart19-Aug-10 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.