home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / msdos / programm / 11347 < prev    next >
Encoding:
Internet Message Format  |  1992-12-11  |  2.3 KB

  1. Path: sparky!uunet!stanford.edu!snorkelwacker.mit.edu!ai-lab!zurich.ai.mit.edu!pshuang
  2. From: pshuang@zurich.ai.mit.edu (Ping Huang)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Re: Calling convention: C vs PASCAL
  5. Date: 11 Dec 92 21:37:38
  6. Organization: M.I.T. Artificial Intelligence Lab.
  7. Lines: 34
  8. Distribution: usa
  9. Message-ID: <PSHUANG.92Dec11213738@freeside.ai.mit.edu>
  10. References: <1992Dec11.225015.26304@eng.ufl.edu>
  11. NNTP-Posting-Host: freeside.ai.mit.edu
  12. In-reply-to: zzang@stat.ufl.edu's message of Fri, 11 Dec 92 22:50:15 GMT
  13.  
  14. In article <1992Dec11.225015.26304@eng.ufl.edu> zzang@stat.ufl.edu (zzang) writes:
  15.  
  16.  > Hello, the C pushs the arg from right to left onto the stack when
  17.  > calling a function.  the PASCAL pushs the args from left to right.  I
  18.  > was told that the C calling convention results in larger as well as
  19.  > slower program.  (due to some cleanup work of the stack after call??)
  20.  > 
  21.  > can someone tell me why ?
  22.  
  23. The C calling convention permits variable length parameter lists (c.f.
  24. the printf() family in the C run-time library, and check your compiler
  25. documentation if it supports the set of macros which allows you to write
  26. your own functions with similar capabilities), because the leftmost
  27. parameters, which are specified, are at the top of the stack, so the
  28. called function doesn't need to know how many more parameters are on the
  29. stack to be able to access the specified ones. The Pascal convention
  30. does not permit this.
  31.  
  32. However, the price for this flexibility is that the called function
  33. cannot contain code to pop the parameters off the stack at its epilogue,
  34. so the code calling the function must do so. Therefore, if you don't
  35. take advantage of variable-length parameters lists, compiling a function
  36. with Pascal-passing-convention as opposed to C-passing-convention means
  37. that the resulting executable code will be smaller -- in the former
  38. case, the code to pop the parameters from the stack appears once, in the
  39. latter case, the code appears as often as your program code lists a call
  40. to the function (note this is different from how many times your program
  41. actually calls the function at run-time).
  42.  
  43. --
  44. | Ping Huang (INTERNET: pshuang@martigny.ai.mit.edu) speaking for himself.
  45. | "One Thing to name them all, One Thing to define them,
  46. |  One Thing to place them in environments and bind them..."
  47.  
  48.