In the 1989 C standard (and earlier pre-standard version of C), a function was implicitly declared by any attempt to call it. The implicit declaration was of the function accepting a variable list of arguments, and returning int
.
So, since your printf()
statement calls f1()
without a preceding declaration of f1()
, the compiler assumes it is a function that returns int
(and can accept any number of arguments). The behaviour is then undefined, since the function is subsequently defined to return void
(i.e. it is not consistent with the implicit declaration).
Under C99 and later, this will normally result in a compilation error. Most C89 compilers accept implicit declarations silently by default, but can be configured (higher warning levels) to give a warning. Some compilers from some vendors (notably gcc) continue to support the implicit declaration even when compiling for later C standards, and are still configured by default to not give a warning.
Note 1: if your compiler accepts an implicit declaration of f1()
, it will probably also compile without the #include <stdio.h>
- since printf()
will also be implicitly declared.
Note 2: Your definition of f1()
also has undefined behaviour, since b
is uninitialised and of automatic storage duration. Accessing its value, let alone incrementing it, therefore gives undefined behaviour.