home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / msdos / programm / 11424 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.4 KB  |  49 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!usenet.coe.montana.edu!news.u.washington.edu!uw-beaver!fluke!plato!rsmith
  3. From: rsmith@plato.ds.boeing.com (Randall E Smith)
  4. Subject: Re: Calling convention: C vs PASCAL
  5. Message-ID: <BzBI1K.5v8@plato.ds.boeing.com>
  6. Organization: Boeing Defense & Space Group
  7. References: <1992Dec11.225015.26304@eng.ufl.edu> <dmurdoch.225.724125846@mast.queensu.ca>
  8. Date: Tue, 15 Dec 1992 20:24:55 GMT
  9. Lines: 38
  10.  
  11. In article <dmurdoch.225.724125846@mast.queensu.ca> dmurdoch@mast.queensu.ca (Duncan Murdoch) writes:
  12. >
  13. >The important difference between standard C and Pascal calling conventions 
  14. >is that in C, it's up to the caller to clean up the stack, while in Pascal 
  15. >it's up to the called routine.  It's this difference that gives the Pascal 
  16. >convention the edge:  every time you call a C-convention routine you need to 
  17. >fix up the stack afterward, while a Pascal-convention routine does 
  18. >it in just one place.  On a PC, there's even a special form of RET to 
  19. >support the Pascal convention.  
  20. >
  21. >The advantage of the C convention is that it makes it easy to call routines 
  22. >variable numbers of parameters.
  23. >
  24. >Duncan Murdoch
  25. >dmurdoch@mast.queensu.ca
  26.  
  27. The calling conventions for C programs are NOT standard, but are left up to
  28. the discretion of the compiler vendor.  So far, all compilers I've looked at do
  29. push parameters from right to left, but the responsibility of cleaning up
  30. the stack may vary.  The default method used by the MetaWare High C compiler
  31. has the caller adjusting the stack after returning from the called function.  
  32. A different compiler (Intermetrics) requires the called function to clean up 
  33. the first parameter (with the RET n instruction) and has the caller clean up 
  34. the rest.  This was probably done to improve performance for functions passing 
  35. only one argument while maintaining the flexibility in passing a variable numbers 
  36. of parameters.
  37.  
  38. Neither one of these techniques is compatible with Intel call gates, used in
  39. protected mode to call more-privileged functions (e.g.: from ring 3 to ring 0.)
  40. An inter-level call gate requires that the called function remove all parameters
  41. from the stack.
  42.  
  43. As an aside, the MetaWare High C compiler does allows you to change the calling
  44. conventions 'on-the-fly.'  This makes it convenient to link MetaWare object
  45. modules with those generated by Pascal or Fortran compilers.
  46.  
  47. Randy Smith
  48.  
  49.