Parameter mismatch legality question

Henry Spencer henry at zoo.toronto.edu
Sat Nov 17 04:10:30 AEST 1990


In article <1990Nov15.224353.155 at mozart.amd.com> tim at proton.amd.com (Tim Olson) writes:
>	foo();

This appears to be meant as a declaration of `foo'; it is not legal as one
in ANSI C.  `int foo();' would be.

>		foo(a);
>	foo(a, b, c, d)
>i.e. the call to a function passes fewer parameters than are declared
>in the function declaration.

In the absence of prototypes, the effect is undefined (3.3.2.2), so your
compiler is entitled to generate code that calls the Soviet embassy, sends
your program, and then tips off the FBI that you are committing espionage.
Or if it's feeling nice, it might give you an error message.

In the presence of prototypes, a number-of-arguments mismatch is illegal
and must be diagnosed.

>Since C's parameters are "call-by-value", they can normally be
>modified or destroyed by the called function.  What if a compiler with
>dataflow analysis decided that the lifetimes for the parameter "b" and
>a local variable were non-overlapping, and decided to use the same
>space (be it memory or a register) to hold them?  In the case above,
>it could end up overwriting some local variable from procedure bar()!

Given the undefinedness of the situation, that is perfectly legitimate.
I would recommend fixing the code.
-- 
"I don't *want* to be normal!"         | Henry Spencer at U of Toronto Zoology
"Not to worry."                        |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list