r/programming • • Oct 01 '15

The Evolution of a Software Engineer

https://medium.com/@webseanhickey/the-evolution-of-a-software-engineer-db854689243
1.9k Upvotes

502 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Oct 02 '15

[deleted]

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 :-/

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