Xref: utzoo comp.lang.c:33907 comp.std.c:3933 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!apple!veritas!amdcad!mozart.amd.com!usenet From: tim@proton.amd.com (Tim Olson) Newsgroups: comp.lang.c,comp.std.c Subject: Parameter mismatch legality question Message-ID: <1990Nov15.224353.155@mozart.amd.com> Date: 15 Nov 90 22:43:53 GMT Sender: usenet@mozart.amd.com (Usenet News) Organization: Advanced Micro Devices; Sunnyvale, CA Lines: 47 Here is an interesting question that came up recently. What is the "legality" of the following ("dusty deck" K&R, not ANSI) code: foo(); bar() { int a; . . foo(a); . . } foo(a, b, c, d) int a, b, c, d; { . . } i.e. the call to a function passes fewer parameters than are declared in the function declaration. 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()! So the question is, is the code: a) Legal in all cases (at least for K&R C) b) Legal if there is no explicit modification of "optional" variables c) Illegal d) Other? -- -- Tim Olson Advanced Micro Devices (tim@amd.com)