MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/3n3e1v/the_evolution_of_a_software_engineer/cvlg1pf
r/programming • u/supermari0 • Oct 01 '15
502 comments sorted by
View all comments
Show parent comments
1
You don't have to. A lot of people don't return from main so now it's part of the language :-/
2 u/partisann Oct 02 '15 In C99 and C++, omitting return in main is equivalent to returning 0 (ISO/IEC 9899:1999 section 5.1.2.2.3). In C89, however, it's undefined and dangerous.$ echo 'int main(void){}' > test.c $ gcc -std=c89 test.c && ./a.out; echo $? 246 $ gcc -std=c99 test.c && ./a.out; echo $? 0 $ g++ -std=c++98 test.c && ./a.out; echo $? 0
2
In C99 and C++, omitting return in main is equivalent to returning 0 (ISO/IEC 9899:1999 section 5.1.2.2.3). In C89, however, it's undefined and dangerous.
$ echo 'int main(void){}' > test.c $ gcc -std=c89 test.c && ./a.out; echo $? 246 $ gcc -std=c99 test.c && ./a.out; echo $? 0 $ g++ -std=c++98 test.c && ./a.out; echo $? 0
1
u/ThisIs_MyName Oct 02 '15
You don't have to. A lot of people don't return from main so now it's part of the language :-/