candide said:
Does the following code
/* -------------------------- */
#include <stdio.h>
/* Function definition with empty parameters list hence test() has no
parameter */
void test()
{
printf("test\n");
}
int main(void)
{
/* The number of arguments doesn't match the number of parameters */
test(42);
return 0;
}
/* -------------------------- */
contain an undefined behavior ?
A declaration that does not specify any parameters, not even "void",
is not normally considered to qualify as a function prototype, which
is required to identify the number and types of the function's
parameters. However, it has been argued that such a declaration, when
it occurs as part of the function definition, which is visible in the
same scope as the function call, does qualify as a prototype, becaue,
as part of a function definition, it does clearly identify the number
of parameters as being 0.
Rather than reopening that controversy, I'll just point out that the
behavior is undefined, whether or not the definition of test()
qualifies as a prototype.
If it is a prototype, then 6.5.2.2p2 applies: "If the expression that
denotes the called function has a type that includes a prototype, the
number of arguments shall agree with the number of parameters." This
is constraint violation, for which a diagnostic is required; an
implementation is not required to accept such code, but if it chooses
to do so, the standard does not define what the behavior of the
resulting program will be.
If it is not a prototype, then 6.5.2.2p6 applies: "If the expression
that denotes the called function has a type that does not include a
prototype ... If the number of arguments does not equal the number of
parameters, the
behavior is undefined."