Versions Compared

Key

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

Two or more incompatible declarations of the same function or object must not appear in the same program  program because they result in undefined behavior. Subclause 6.2.7 of the C Standard mentions that two types may be distinct yet compatible and addresses precisely when two distinct types are compatible.

...

In this noncompliant code example, the variable a is declared to have pointer type in file a.c but defined to have array type in file b.c. The two declarations are incompatible, resulting in undefined behavior 15. As before, accessing the object in function f() results in undefined behavior 37 with the typical effect of triggering a hardware trap.

...

Noncompliant Code Example (Incompatible Variadic Function Declarations)

In this noncompliant code example, the function buginf() is defined to take a variable number of arguments and expects them all to be signed integers, with a sentinel value of -1:

...