I assume when you say that it does not work in the second code example, you mean that you get a compile time error.
The reason is that when there is an implicit function declaration, it is assumed to take a fixed number of arguments, and return int
. However, mymethod()
is first implicitly declared, and then later declared to return void
. This is an error since the new declaration does not match the previous (implicit) declaration.
C90 (ANSI C89) allowed implicit function declarations. From C89, Section 3.3.2.2:
If the expression that precedes the parenthesized argument list in
a function call consists solely of an identifier, and if no
declaration is visible for this identifier, the identifier is
implicitly declared exactly as if, in the innermost block containing
the function call, the declaration
extern int identifier();
appeared.
However, this allowance has been removed as of C99 (and hence also disallowed in C11). C++ never allowed implicit function declarations.