Reputation: 68033
In C the following horror is valid:
myFunc()
{
return 42; // return type defaults to int.
}
But, what about in C++? I can't find a reference to it either way...
My compiler (Codegear C++Builder 2007) currently accepts it without warning, but I've had comments that this is an error in C++.
Upvotes: 6
Views: 5341
Reputation: 68033
So, it's definitely 'ill formed' C++, but it seems many compilers accept it with a warning at best.
Please add to/correct this list!
Upvotes: 5
Reputation: 6849
As posted, it is ill-formed. MSVC 8 gives the following error:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Upvotes: 2
Reputation: 101456
This is not legal C++, but some compilers will accept it either silently or with a diagnostic.
Upvotes: 2
Reputation: 13973
Implicit return types are valid in C89, but a lot of compilers warn about it.
They are not valid in C++, nor in C99.
Upvotes: 10
Reputation: 506925
It's ill-formed in C++. Meaning that it doesn't compile with a standard conforming compiler. Paragraph 7.1.5/4 in Annex C of the Standard explains the change "Banning implicit int".
Upvotes: 20