home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18232 < prev    next >
Encoding:
Text File  |  1992-12-11  |  1.8 KB  |  52 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ufo!kaleb
  3. From: kaleb@jpl-devvax.jpl.nasa.gov (Kaleb Keithley)
  4. Subject: Re: Calling convention: C vs PASCAL
  5. Message-ID: <1992Dec12.011122.2786@jpl-devvax.jpl.nasa.gov>
  6. Organization: Jet Propulsion Laboratory (NASA)
  7. References: <1992Dec11.225756.26780@eng.ufl.edu>
  8. Distribution: usa
  9. Date: Sat, 12 Dec 1992 01:11:22 GMT
  10. Lines: 40
  11.  
  12. In article <1992Dec11.225756.26780@eng.ufl.edu> zzang@stat.ufl.edu (zzang) writes:
  13. >Hello,
  14. >the C pushs the args from right to left onto 
  15. >the stack when calling a function.
  16.  
  17. Correct so far...  For simplicity sake, we'll assume that all parameters
  18. are passed on the stack.
  19.  
  20. >the PASCAL pushs the args from left to right.
  21.  
  22. Usually, but not necessarily so.  And it's Pascal, not PASCAL.
  23.  
  24. >I was told that the C convention results in
  25. >larger as well as slower program.
  26. >(due to some cleanup work of the stack
  27. >after call??)
  28.  
  29. Maybe, then maybe not.
  30.  
  31. >can someone tell me why?
  32.  
  33. Because C supports a variable number of arguments, it's necessary to
  34. push parameters in an order that places the "first" parameter in a known
  35. place on the stack.  
  36.  
  37. This also means that in C, the "caller" must restore the stack after a
  38. function call, because only the caller knows how many arguments were
  39. pushed on the stack.  The "called" function or procedure can (and does
  40. in the Pascal compilers I've used) restore the stack; because it knows
  41. how many parameters were pushed onto it.
  42.  
  43. It's basically (no pun intended) a question of where the steps get done.
  44. Both have to do the same thing.  Unless some compiler generates (lots of)
  45. extra dead or no-op instructions in the process, both should be equally
  46. fast.  Delta the efficiency of the runtime and I/O libraries.
  47.  
  48. -- 
  49.  
  50. Kaleb Keithley                               kaleb@jpl-devvax.jpl.nasa.gov
  51.  
  52.