Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • an ambiguous functional interface between the caller and callee.
  • sensitive information outflow.

A similar recommendation deals with parameter type in a more general sense: DCL07-C. Include the appropriate type information in function declarators.

...

In this compliant solution, void is specified explicitly as a parameter in the declaration of foo's prototype.:

Code Block
bgColor#ccccff
langc
/* in foo.h */
void foo(void);

/* in foo.c */
void foo(void) {
  int i = 3;
  printf("i value: %d\n", i);
}

/* in caller.c */
#include "foo.h"

foo(3);

...

When the compliant solution is used and foo(3) is called, the GCC compiler issues the following diagnostic, which alerts the programmer about the misuse of the function interface.:

Code Block
error: too many arguments to function ‘foo’

...

In C++, foo() and foo(void) have exactly the same meaning and effect, so this rule doesn't apply to C++. However, foo(void) should be declared explicitly instead of foo() to distinguish it from foo(...), which accepts an arbitrary number and type of arguments.

Bibliography

[ISO/IEC 9899:2011]Section 6.7.6.3, "Function Declarators (including Prototypes)"
Section 6.11.6, "Function Declarators"
[TIGCC, void usage]Manual, "C Language Keywords": void

...