Xref: utzoo comp.lang.c:9144 comp.sys.ibm.pc:14318 Path: utzoo!utgpu!utcsri!flaps From: flaps@utcsri.UUCP (Alan J Rosenthal) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: cdecl keyword Message-ID: <5980@utcsri.UUCP> Date: 11 Apr 88 05:22:57 GMT Article-I.D.: utcsri.5980 Posted: Mon Apr 11 01:22:57 1988 References: <1238@wjvax.UUCP> <297@ho7cad.ATT.COM> <1242@wjvax.UUCP> <185@premise.ZONE1.COM> <7046@ki4pv.uucp> Organization: University of Toronto Lines: 35 Summary: chang@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@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 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