Why is implicitly declaring functions problematic?

What are/were the perceived problems with supporting implicit declaration of functions in code?

1,665 1 1 gold badge 4 4 silver badges 26 26 bronze badges

asked Jun 7, 2023 at 17:17

9,053 2 2 gold badges 31 31 silver badges 90 90 bronze badges

3 Answers 3

$\begingroup$

There may be a design space where implicit function declarations are desirable, such as when synthesising functions from structural effect handlers or struct fields, however C's approach is problematic for a simple reason: it assumes an unknown function to be of type int() and to be extern .
This means it works with printf , but not with malloc , nor atof .
It did make some sense for such a feature to exist in early C, as almost all routines from its stdlib returned either void or int , and as () makes a function variadic, however, for C99 the Committee decided to remove implicit declarations, justifying its action as so:

25 A new feature of C99: The rule for implicit declaration of functions has been removed in C99. The effect is to guarantee the production of a diagnostic that will catch an additional category of programming errors. After issuing the diagnostic, an implementation may choose to assume an implicit declaration and continue translation in order to support existing programs that exploited this feature.