Skip to content

Remove type from main (c and cpp)#120

Open
cpiber wants to merge 2 commits intomathiasbynens:masterfrom
cpiber:master
Open

Remove type from main (c and cpp)#120
cpiber wants to merge 2 commits intomathiasbynens:masterfrom
cpiber:master

Conversation

@cpiber
Copy link

@cpiber cpiber commented Jul 24, 2021

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
Copy link

angleKH commented Nov 9, 2021

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
Copy link
Author

cpiber commented Nov 9, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants