home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ufo!kaleb
- From: kaleb@jpl-devvax.jpl.nasa.gov (Kaleb Keithley)
- Subject: Re: Calling convention: C vs PASCAL
- Message-ID: <1992Dec12.011122.2786@jpl-devvax.jpl.nasa.gov>
- Organization: Jet Propulsion Laboratory (NASA)
- References: <1992Dec11.225756.26780@eng.ufl.edu>
- Distribution: usa
- Date: Sat, 12 Dec 1992 01:11:22 GMT
- Lines: 40
-
- In article <1992Dec11.225756.26780@eng.ufl.edu> zzang@stat.ufl.edu (zzang) writes:
- >Hello,
- >the C pushs the args from right to left onto
- >the stack when calling a function.
-
- Correct so far... For simplicity sake, we'll assume that all parameters
- are passed on the stack.
-
- >the PASCAL pushs the args from left to right.
-
- Usually, but not necessarily so. And it's Pascal, not PASCAL.
-
- >I was told that the C convention results in
- >larger as well as slower program.
- >(due to some cleanup work of the stack
- >after call??)
-
- Maybe, then maybe not.
-
- >can someone tell me why?
-
- Because C supports a variable number of arguments, it's necessary to
- push parameters in an order that places the "first" parameter in a known
- place on the stack.
-
- This also means that in C, the "caller" must restore the stack after a
- function call, because only the caller knows how many arguments were
- pushed on the stack. The "called" function or procedure can (and does
- in the Pascal compilers I've used) restore the stack; because it knows
- how many parameters were pushed onto it.
-
- It's basically (no pun intended) a question of where the steps get done.
- Both have to do the same thing. Unless some compiler generates (lots of)
- extra dead or no-op instructions in the process, both should be equally
- fast. Delta the efficiency of the runtime and I/O libraries.
-
- --
-
- Kaleb Keithley kaleb@jpl-devvax.jpl.nasa.gov
-
-