Xref: utzoo comp.lang.c:8768 comp.sys.ibm.pc:13952 Path: utzoo!utgpu!water!watmath!clyde!rutgers!tut.cis.ohio-state.edu!husc6!cca!mirror!premise!chang From: chang@premise.ZONE1.COM (John Chang) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: cdecl keyword Summary: Why cdecl is a keyword Keywords: cdecl MicroSoft C keywords Message-ID: <185@premise.ZONE1.COM> Date: 2 Apr 88 09:18:23 GMT References: <1238@wjvax.UUCP> <297@ho7cad.ATT.COM> <1242@wjvax.UUCP> <3867@super.upenn.edu> Organization: Premise, Inc., Cambridge, MA Lines: 59 Roberto Shironoshita writes: > Rahul Dhesi writes: > >[ cc -pascal mystuff.c ] > >If mystuff.c uses any C library function, you still want that library > >function to be called using the C calling convention, even though you > >asked the compiler to generate code for the Pascal calling convention. > > I would much rather do away with the switch to generate foreign > calling conventions, and assume anything is a C function unless > otherwise declared. > >With a little foresight Microsoft could have just used the same calling > >convention in all its language translators. > > I am of the belief that most languages have their own calling > conventions: FORTRAN uses pass-by-reference for everything (at least, > that's what I heard last); PASCAL uses pass-by-value for regular > parameters, and pass-by-reference for VAR parameters. C uses > pass-by-value for everything. ^^^^^^^^^^ What about arrays? The calling convention we're talking about here isn't call-by-name or call-by-value. It's simply the order in which parameters are passed on the stack. And in C, that order *must* be right to left in order to support variable length functions like printf. If it were left to right, then the printf function wouldn't know where to find its format string. However, the right to left parameter passing takes more code space (one extra instruction to fix the stack after a function call) and hence takes longer to execute than 'pascal' calling convention (left-to-right parameter passing). That's the reason the cdecl and pascal keywords exist. Although Microsoft could have made all their languages use the same parameter passing convention, this would have meant generating less efficient code. The extra instruction needed to pop the stack after a function call seems unimportant, yet I once heard Microsoft claim that the change to pascal calling convention made Microsoft Windows "substantially" smaller and faster. I don't remember the figures, but they were hard to believe. If you're writing functions with a variable number of parameters, and want to take advantage of the more efficient pascal calling convention, you still have to worry about the portability of these keywords. One solution is to #define environment-dependent tokens for the keywords. How about the far and huge keywords? Parsing declarations was bad enough without these. Quick, what's the difference between far int (*f)() and int far (*f)()? But this is more a gripe about the Intel architecture than anything else. John Chang { ...harvard!eddie,...cbosgd!mirror}!premise!chang Premise, Inc. chang@premise.zone1.com 3 Cambridge Center Cambridge, MA 02142 (617) 225-0422 When you have the advantage, get the money out.