[comp.lang.c] variable numbers of arguments in ANSI C programs

gnu@hoptoad.uucp (John Gilmore) (12/27/87)

> In article <3726@hoptoad.uucp> gnu@hoptoad.uucp (John Gilmore) writes:
> >Another thing that ANSI C disallows is ALL prior uses of functions
> >with variable numbers of arguments.  All such functions must be declared
> >and defined with ", ..." notation, which did not exist before ANSI C.

kanner@apple.UUCP (Herbert Kanner) wrote:
> Not quite.  Take printf for example.  True, it has to be defined with
> the (format, ...) notation, but it is a library function and not your
> problem.  Declarations of the form int printf(); are completely
> acceptable; see Section 3.5.3.3, which states: "... an empty list in a
> function declaratorthat is not part of a function definition specifies
> that no information about the number or types of the parameters is
> supplied."

3.3.2.2 says "If no function prototype declarator is in scope...if the
number of arguments does not agree with the number of formal parameters,
the behaviour is undefined."  If there is no information on the number
of arguments, does the number "agree"?  I don't know.

I have to keep reminding myself of the difference between DECLARATION
and DEFINITION as I read this stuff.  Declaration is when you just tell the
compiler the type.  Definition is when you give the whole function.
Variable argument list functions must be DEFINED with ",..." (3.7.1).
It's no longer clear to me that they have to be DECLARED with ",...",
but this is worse: now the compiler can't tell at the point of function
call whether the function is vararg or not: so it has to use the same
calling sequence for both.  Part of the point of prototype declarations
is to allow called routines to pop their parameters (which on many machines
generates better code), but 3.3.2.2 makes it possible to DEFINE a
function with prototypes, but call it with a non-prototype DECLARATION,
if the parameter types used are compatible.  This means that even functions
DEFINEd with prototypes must let their caller pop the arguments.

Sigh...
-- 
{pyramid,ptsfa,amdahl,sun,ihnp4}!hoptoad!gnu			  gnu@toad.com
  I forsee a day when there are two kinds of C compilers: standard ones and 
  useful ones ... just like Pascal and Fortran.  Are we making progress yet?
	-- ASC:GUTHERY%slb-test.csnet