Does C ++ provide valid return types for functions?

The following horror acts in C:

myFunc()
{
  return 42;  // return type defaults to int.
}

But what about in C ++? I can not find a link to it anyway ...

My compiler (Codegear C ++ Builder 2007) is currently accepting it without warning, but I have comments that this is a bug in C ++.

+5
source share
5 answers

It is poorly formed in C ++. This means that it does not compile with the standard appropriate compiler. Paragraph 7.1.5 / 4 in Appendix C of the Standard explains the change to "Prohibit Implicit Int".

+16
source

C89, .

++, C99.

+8

, " " ++, , , .

  • Codegear ++ Builder 2007:
  • g++: -W -Wall - (Piotr)
  • MSVC 8: (tfinniga)
  • ...?

Please add / edit this list!

+4
source

This is not legal C ++, but some compilers accept it either silently or through diagnostics.

+2
source

As indicated, it is poorly formed. MSVC 8 gives the following error:

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
+1
source

All Articles