Versions Compared

Key

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

...

Noncompliant Code Example (ambiguous interface)

Code Block
bgColor#FFCCCC

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

...

/* caller */
    foo(3);

In this particular example, caller gives a call to foo with parameter specified as 3. Because function foo() is declared without void, the compiler will not perform caller check. Due to the accidental internal implementation, the function foo() outputs i value: 3 which matches with caller's temptation. In an inherited code base where foo and caller are developed at different time, this leads to caller's belief that foo actually accept one integer as parameter and foo will output the corresponding message when parameter is changed.

In fact, no parameter specified for a function has the same meaning as arbitrary paramemters, which means the caller can feed arbitrary number of parameters to the function. Arbitrary parameter list is useful for system logging purpose, e.g., but not the callee's intention in other situation.

Code Block
bgColor#FFCCCC

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

...

/* caller */
    foo(3);

Compliant Solution (ambiguous interface)

In this example, void is explicitly specified as a parameter.

Code Block
bgColor#ccccff
/* compile using gcc4.3.3 */
void foo (void) {
    int i = 3;
    printf("i value: %d\n", i);
}

...

Noncompliant Code Example (information outflow)

...