cdecl keyword

Alan J Rosenthal flaps at utcsri.UUCP
Mon Apr 11 15:22:57 AEST 1988


chang at premise.ZONE1.COM (John Chang) wrote that in C parameters must be
pushed in right-to-left order to support functions with a variable
number of arguments (henceforth known as `variadic' functions).

tanner at ki4pv.uucp (T. Andrews) cited a compiler which pushes its
arguments left-to-right, handling a pre-determined list of variadic
functions (i.e. including printf()) as special cases, pushing
(invisibly to the user) an extra word containing the argument count.

My comment is:  Such a compiler would not correctly compile all correct
C programs.  In C it is permissible to call any function (including
user-defined ones) with the wrong number of arguments, so long as any
arguments not actually passed are not accessed by the function being
called.  The accessing can be done in printf style, although variable
types and unlimited numbers of arguments are not supported.

(It is also possible to use the <varargs.h> package on compilers which
support it, but presumably the cited compiler did not, which is fine.
The varargs.h package provides functionality like that required to
implement printf, at the expense of additional awkwardness.)

The new ANSI C standard will change all this (as well as nearly
everything else!).  It prohibits calls to variadic functions except in
scope of a declaration which says that that function is variadic; I
believe that it also requires that varargs.h be used (but they've
changed the name).

This new rule will validate the cited compiler's behaviour if it is
upgraded to be an ANSI standard C compiler, and also sort of
retroactively validates its previous behaviour by saying that the old
standard's allowing of implicitly variadic functions wasn't very
important.

ajr



More information about the Comp.lang.c mailing list