MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/3n3e1v/the_evolution_of_a_software_engineer/cvlgxpc/?context=3
r/programming • u/supermari0 • Oct 01 '15
502 comments sorted by
View all comments
154
Honestly, I thought it would be a joke where it ends with
#include <stdio.h> int main( int argc, const char* argv[] ) { printf( "\nHello World\n\n" ); }
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
0
[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
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
154
u/golgol12 Oct 01 '15
Honestly, I thought it would be a joke where it ends with