Variable Numbers of Args to Functions in ANSI C.

Steve Klein sklein at bonnie.ics.uci.edu
Sun Apr 30 17:00:00 AEST 1989


If I forward-declare the function:

	int func(a, b, ...);

Then how do I define and call 'func'?

I tried:
    	#include <varargs.h>

    	int func(a, b, va_alist);
    	int a, b;
    	va_dcl
    	{
    	    ...
    	}

but GNU CC says 'number of args doesn't match prototype'.

Trying
    	int func(a, b, c, d);
    	int a, b, c, d;
    	{
    	    ..casting c & d where appropriate..
    	}

this, of course, moans when I call func without all 4 params:

    	func (actual_a, actual_b);

I _thought_ in ANSI C that the trailing '...' told the compiler not to
check the number or types of the parameters that followed. Is there a way
to do this, or does one need C++ with its overloading for this kind of stuff?
I could use the -traditional switch on gcc, but I'd like _some_ kind of
type checking! Is this a compiler bug or something I don't understand
about ANSI?



More information about the Comp.std.c mailing list