Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: xferred bugint() NCCE/CS from EXP37-C since it violated that rule

...

Code Block
bgColor#ccccff
langc
/* In a.c */
extern int f(int a);   

int g(int a) {
  return f(a);   
}

/* In b.c */
int f(int a) {   
  return a * 2;
}

Noncompliant Code Example (Incompatible Variadic Function Declarations)

In this noncompliant 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:

Code Block
bgColor#FFCCCC
langc
/* In a.c */
void buginf(const char *fmt, ...) {
   /* ... */
}
 
/* In b.c */
void buginf();

While this code appears to be well-defined due to the prototype-less declaration of buginf(),this code exhibits undefined behavior per subclause 6.7.6.3 paragraph 15 [ISO/IEC 9899:2011]:

For two function types to be compatible, both shall specify compatible return types.146) Moreover, the parameter type lists, if both are present, shall agree in the number of parameters and in use of the ellipsis terminator; corresponding parameters shall have compatible types. If one type has a parameter type list and the other type is specified by a function declarator that is not part of a function definition and that contains an empty identifier list, the parameter list shall not have an ellipsis terminator and the type of each parameter shall be compatible with the type that results from the application of the default argument promotions.

Compliant Solution (Incompatible Variadic Function Declarations)

In this compliant solution, the prototype for the function buginf() is included in the scope in the source file where it will be used:

Code Block
bgColor#ccccff
langc
/* In a.c */
void buginf(const char *fmt, ...) {
   /* ... */
}

/* In b.c */
void buginf(const char *fmt, ...);

Anchor
Excessively Long Identifiers
Excessively Long Identifiers

Noncompliant Code Example (Excessively Long Identifiers)

...