Parameter mismatch legality question
    Tim Olson 
    tim at proton.amd.com
       
    Fri Nov 16 09:43:53 AEST 1990
    
    
  
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 at amd.com)
    
    
More information about the Comp.std.c
mailing list