From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ac02560f0af03a21 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-31 06:45:20 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny03.gnilink.net.POSTED!0f19ed38!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: <3FEC43B2.5080606@noplace.com> <1072450300.440355@master.nyc.kbcfp.com> <3FEC4E89.2070804@noplace.com> <1072458199.346049@master.nyc.kbcfp.com> <3fec7c21$0$4764$61fed72c@news.rcn.com> Subject: Re: GNAT parameter passing, C-style? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: <4iBIb.8173$qS3.498@nwrdny03.gnilink.net> Date: Wed, 31 Dec 2003 14:45:20 GMT NNTP-Posting-Host: 151.203.242.46 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny03.gnilink.net 1072881920 151.203.242.46 (Wed, 31 Dec 2003 09:45:20 EST) NNTP-Posting-Date: Wed, 31 Dec 2003 09:45:20 EST Xref: archiver1.google.com comp.lang.ada:3988 Date: 2003-12-31T14:45:20+00:00 List-Id: "Keith Thompson" wrote in message news:lnekul8ewd.fsf@nuthaus.mib.org... > "Frank J. Lhota" writes: > > I don't believe it was stated explicitly, but the standard C calling > > convention (arguments pushed on the stack in reverse order, and popped off > > by the callee) is implied by the requirements for variable argument > > functions. > [...] > > No, it isn't. In standard C, functions with variable argument lists > have a special syntax ("..."), and don't have to use the same calling > conventions as other functions. In the body of such a function, it > accesses its arguments using special macros defined in the header > ; these macros can do whatever compile-specific magic is > necessary. In vanilla (i.e. original K&R) C, there are no argument lists in function declarations. For that matter, vanilla C does NOT even require functions declarations. If an undeclared function is called in vanilla C, the unconverted argument list is assumed to be OK, the calling convention is assumed to be C, and it is assumed that the function returns an int. ANSI C depreciates this loose approach to functions. ANSI C strongly encourages the full declaration of all functions used, including argument lists. For compatability, however, ANSI C accepts function declarations with no argument lists (e.g. "double sin();"), as well as the calling of undeclared functions. Since there is no requirement that the user will declare a function's argument list (or the function for that matter), a C compiler may not be able to tell whether a function accepts a variable argument list or not. For that reason, C compilers have to assume the C calling convention, unless the user indicates via declaration or command line options. Every C compiler that I have worked with uses the C calling convention by default when compiling C (as opposed to C++) code. If you know of a C compiler that works differently, please post the details. I'm not saying this because out of fondness for the C calling convention. Although this convention is required to handle variable argument lists, it is less efficient for the vast majority of cases where the function has a fixed parameter list. Fortunately, C++ has resolved this problem by making a clean break from vanilla C. They do require that functions must be declared, including its parameter list, for it to be used. The compiler can always determine if a function has a variable argument list, and hence can (and does) reserve the C calling conventions for only those functions that require it.