Why is explicit returning 0 from main () considered good practice?

Possible duplicate:
return statement vs exit () in main ()

I just read the first chapter of Accelerated C ++ (it seems like a terrific book), and in the end the author says

However, explicitly including a return from main is good practice.

Why is this considered good practice? In C99, I always skipped return 0using exit()to signal abnormal termination of a program and never skipped an explicit return.

+3
source share
5 answers

C99 ++, main(), return 0;. C90 - main() return ( , undefined).

, "Accelerated ++" , , . , , , C90, , .

+4

,

-, main int,

-, , , ++, exit() main main.

+7

( ) , .

.

, .

+1

, exit() , main(), , return 0, .

, main() - , , . - .

+1

++ main() int. , , , ( 0 ), .

I will give a specific Microsoft example, but it shows the general need to return an error code: ProcessA needs to create a ProcessB and wait for it to complete, after which it wants to check if ProcessB has been processed successfully. ProcessA will use the CreateProcess function to create the ProcessB, then it will use the ProcessB handle to wait for it to complete, and then it will use GetExitCodeProcess to get the ProcessB termination code - which is the int value returned from main ().

-1
source

Source: https://habr.com/ru/post/1775074/


All Articles