The following code is rejected in GCC with pedantic mode enabled: enum E{e=-1}; _Static_assert( _Generic((enum E)e,int:1,default:0), "incorrect enumeration type" ); enum E main(){} If the static assertion succeeds, then the type enum E is compatible with int. Given that enum E is compatible with int, it should be a valid return type of main: > If the return type of the main function is a type compatible with int, > a return from the initial call to the main function is equivalent to > calling the exit function with the value returned by the main function > as its argument; reaching the } that terminates the main function returns > a value of 0. If the return type is not compatible with int, the termination > status returned to the host environment is unspecified. Section 5.1.2.2.3 "Program termination" Paragraph 1 ISO/IEC 9899:2018 Additionally, here is the paragraph explaining that an enumerated type is compatible with its underlying type: > Each enumerated type shall be compatible with char, a signed integer type, > or an unsigned integer type. The choice of type is implementation-defined, > but shall be capable of representing the values of all the members of the > enumeration. Section 6.7.2.2 "Enumeration specifiers" Paragraph 4 ISO/IEC 9899:2018 Outside of pedantic mode, GCC accepts the code but returns a non-zero value when the closing brace is reached which isn't correct either.
clang even errors out: <source>:6:1: error: 'main' must return 'int' 6 | enum E main(){} | ^~~~~~ | int
From C99 draft: 5.1.2.2.1 Program startup The function called at program startup is named main.The implementation declares no prototype for this function. It shall be defined with a return type ofintand with no parameters ... or with two parameters (referred to here asargcandargv, though anynames may be used, as theyare local to the function in which theyare declared):
C23 working draft has the same wording there too: The function called at program startup is named main.The implementation declares no prototype for this function. It shallbe defined with a return type of int Nowhere it says compatiable with int. just the return type of int.
C23 working draft can be found at https://open-std.org/JTC1/SC22/WG14/www/docs/n3096.pdf .