mathiasbynens / small

Smallest possible syntactically valid files of different types
https://mathiasbynens.be/notes/minimal-html
1.93k stars 184 forks source link

Remove type from main (c and cpp) #120

Open cpiber opened 3 years ago

cpiber commented 3 years ago

In c and cpp, no return type defaults to int.

g++ does not complain at all about this (cpp).

gcc gives a warning (type defaults to ‘int’ in declaration of ‘main’ [-Wimplicit-int]), is this allowed? (c)

angleKH commented 3 years ago

This will not be valid C++. In the C++ standard, the standard mandates that the return type must be int. Compile it with -Wall or pedantic and you will receive this: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type].

As for C, the standard allows implementation defined main functions, but I think we should still stick to the ones that are required by the standard, since these are meant to be c/cpp files and not files for gcc/g++.

cpiber commented 3 years ago

Actually I don't think warnings are an issue, at least one of the C-family programs also only worked with warnings (been a while since I tested). Or is it only those that specifically violate the standard?