Xref: utzoo gnu.gcc:479 comp.lang.c:18231 comp.std.c:1122 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!husc6!bu-cs!composer From: composer@bu-cs.BU.EDU (Jeff Kellem) Newsgroups: gnu.gcc,comp.lang.c,comp.std.c Subject: Re: Variable Numbers of Args to Functions in ANSI C. Message-ID: <30501@bu-cs.BU.EDU> Date: 1 May 89 13:05:24 GMT References: <13024@paris.ics.uci.edu> Reply-To: composer@bu-cs.bu.edu (Jeff Kellem) Followup-To: gnu.gcc Organization: Boston University Lines: 60 In article <13024@paris.ics.uci.edu> sklein@bonnie.ics.uci.edu (Steve Klein) writes: >If I forward-declare the function: > > int func(a, b, ...); > >Then how do I define and call 'func'? > >I tried: > #include > > int func(a, b, va_alist); > int a, b; > va_dcl > { > ... > } > >but GNU CC says 'number of args doesn't match prototype'. GCC is correct with this. For one, is not (as far as I know) part of the ANSI standard. What you want to use is . So, basically what you want in ANSI C for the above is something like the following: #include int func(int, int, ...); ... int func(int a, int b, ...) { va_list arg_pointer; int foo; ... /* Then in here, call va_start(arg_pointer, b); */ /* to initialize the argument pointer to the optional */ /* parameter list. */ va_start(arg_pointer, b); /* Successive calls to va_arg will get the remaining args. */ foo = va_arg(arg_pointer, int); /* Then, finally call va_end to reset everything back to normal. */ va_end(arg_pointer); ... } Hope this helps ... Enjoy ... -jeff Jeff Kellem INTERNET: composer@bu-cs.bu.edu (or composer%bu-cs.bu.edu@bu-it.bu.edu) UUCP: ...!harvard!bu-cs!composer