Xref: utzoo comp.lang.c:33928 comp.std.c:3938 Newsgroups: comp.lang.c,comp.std.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: Parameter mismatch legality question Message-ID: <1990Nov16.171030.19311@zoo.toronto.edu> Organization: U of Toronto Zoology References: <1990Nov15.224353.155@mozart.amd.com> Date: Fri, 16 Nov 90 17:10:30 GMT In article <1990Nov15.224353.155@mozart.amd.com> tim@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@zoo.toronto.edu utzoo!henry