...
In this noncompliant code example, the caller calls foo()
with a parameter of 3an argument of 3. The caller expects foo()
to accept a single int
argument and to output the argument as part of a longer message. Because foo()
is declared without the void
parameter, the compiler will not perform any caller check. Due to the accidental internal implementationIt is therefore possible that the caller may not detect the error. In this example, for instance, the function foo()
outputs might output the value 3 , as the caller expects. In an inherited code base where foo and the caller are developed at different times, the caller will expect foo()
to accept one integer as a parameter and to output the corresponding message when the parameter is changed.expected.
Because no function parameter has the same meaning as an arbitrary parameter, the caller can feed provide an arbitrary number of parameters arguments to the function.
Code Block | ||
---|---|---|
| ||
void foo() { int i = 3; printf("i value: %d\n", i); } ... /* caller */ foo(3); |
...