Article View: comp.windows.x
Article #38350Re: C++ and callbacks
From: Bear Giles
Date: Mon, 09 May 1994 16:31
Date: Mon, 09 May 1994 16:31
66 lines
3746 bytes
3746 bytes
In article <CpJKJz.KBD@news.cis.umn.edu> ianhogg@milli.cs.umn.edu (Ian J Hogg) writes: >In article <JASON.94May6154541@deneb.cygnus.com> jason@cygnus.com (Jason Merrill) writes: >>>>>>> Ian J Hogg <ianhogg@milli.cs.umn.edu> writes: >> >>> Where does anything say that C and C++ use the same calling convention >>> for plain functions. As I've stated before I know of at least one >>> compiler that passes arguments for C++ linkage functions differently than >>> C linkage functions. Are you saying this compiler is broken? >> >>I was only referring to my perception of existing practice; evidently I was >>mistaken. It does seem strange to me that they would alter the calling >>convention, but I suppose they had their reasons. If people followed the language standards, instead of bitching when they got caught with their hands in the cookie jar, nobody would have noticed. (Okay, that's a little strong because most companies do use the same calling conventions -- probably because they see so many people abusing it. However, if you follow the ARM and use "extern C" and never try to call member functions from C, *you would never notice the "problem"*.) >It was the Zortech compiler for SYSV/386. They claimed their "C++" linkage >parameter passing was more efficient. C++ requires all function have prototypes, which allows the compiler to remove arguments from the stack in the *called* function for any function with a fixed number of arguments (99%). Assember code looks like: push _var1 foo: code.. push _var2 ret 4 call foo whatever... C does not require function prototypes (although it will use them if available) and there is nothing to prevent a developer from specifying too many or too few parameters. Therefore, the *calling* function Assember code looks like: push _var2 foo: code.. push _var1 ret call foo pop 4 whatever... The first approach is slightly faster, and is the one normally implemented. It is also the "pascal" convention available on PC compilers, and this performance improvement is why the MS/Windows SDK uses the "pascal" modifier on all procedures. BTW, note that the arguments in the second example were pushed on the stack in reversed order. In C, since you don't know the number of arguments you need to push them from right-to-left, so that the left-most argument is always on the top of the stack. In contrast, in C++ you (generally) know how many arguments are present and you can push them in any order. I believe this also allows a slightly more efficient "stack frame", but am not sure -- my assembler/HL interfaces always used the C conventions. -- Bear Giles bear@fsl.noaa.gov
Technical Details
Message-ID:
<1994May9.163157.3426@fsl.noaa.gov>Path:
arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!usc!howland.reston.ans.net!gatech!newsxfer.itd.umich.edu!ncar!csn!qwerty.fsl.noaa.gov!bora.fsl.noaa.gov!bearReferences:
<CpEBxp.9w2@news.cis.umn.edu> <JASON.94May6154541@deneb.cygnus.com> <CpJKJz.KBD@news.cis.umn.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,ad5a39011a2d3d26 X-Google-Attributes: gid109fba,public X-Google-Thread: 103734,ad5a39011a2d3d26 X-Google-Attributes: gid103734,public X-Google-Thread: 10ba33,ad5a39011a2d3d26 X-Google-Attributes: gid10ba33,public X-Google-ArrivalTime: 1994-05-09 09:56:23 PST Newsgroups: comp.windows.x,comp.lang.c++,gnu.g++.help Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!usc!howland.reston.ans.net!gatech!newsxfer.itd.umich.edu!ncar!csn!qwerty.fsl.noaa.gov!bora.fsl.noaa.gov!bear From: bear@bora.fsl.noaa.gov (Bear Giles) Subject: Re: C++ and callbacks Message-ID: <1994May9.163157.3426@fsl.noaa.gov> Sender: news@fsl.noaa.gov (USENET News System) Organization: Forecast Systems Labs, NOAA, Boulder, CO USA References: <CpEBxp.9w2@news.cis.umn.edu> <JASON.94May6154541@deneb.cygnus.com> <CpJKJz.KBD@news.cis.umn.edu> Date: Mon, 9 May 1994 16:31:57 GMT Lines: 66