🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #6467

Re: Calling convention: C vs PASCAL

#6467
From: Randall E Smith
Date: Tue, 15 Dec 1992 20:24
37 lines
2502 bytes
In article <dmurdoch.225.724125846@mast.queensu.ca> dmurdoch@mast.queensu.ca (Duncan Murdoch) writes:
>
>The important difference between standard C and Pascal calling conventions 
>is that in C, it's up to the caller to clean up the stack, while in Pascal 
>it's up to the called routine.  It's this difference that gives the Pascal 
>convention the edge:  every time you call a C-convention routine you need to 
>fix up the stack afterward, while a Pascal-convention routine does 
>it in just one place.  On a PC, there's even a special form of RET to 
>support the Pascal convention.  
>
>The advantage of the C convention is that it makes it easy to call routines 
>variable numbers of parameters.
>
>Duncan Murdoch
>dmurdoch@mast.queensu.ca

The calling conventions for C programs are NOT standard, but are left up to
the discretion of the compiler vendor.  So far, all compilers I've looked at do
push parameters from right to left, but the responsibility of cleaning up
the stack may vary.  The default method used by the MetaWare High C compiler
has the caller adjusting the stack after returning from the called function.  
A different compiler (Intermetrics) requires the called function to clean up 
the first parameter (with the RET n instruction) and has the caller clean up 
the rest.  This was probably done to improve performance for functions passing 
only one argument while maintaining the flexibility in passing a variable numbers 
of parameters.

Neither one of these techniques is compatible with Intel call gates, used in
protected mode to call more-privileged functions (e.g.: from ring 3 to ring 0.)
An inter-level call gate requires that the called function remove all parameters
from the stack.

As an aside, the MetaWare High C compiler does allows you to change the calling
conventions 'on-the-fly.'  This makes it convenient to link MetaWare object
modules with those generated by Pascal or Fortran compilers.

Randy Smith
Technical Details
Message-ID: <BzBI1K.5v8@plato.ds.boeing.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!usenet.coe.montana.edu!news.u.washington.edu!uw-beaver!fluke!plato!rsmith
References: <1992Dec11.225015.26304@eng.ufl.edu> <dmurdoch.225.724125846@mast.queensu.ca>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!usenet.coe.montana.edu!news.u.washington.edu!uw-beaver!fluke!plato!rsmith
From: rsmith@plato.ds.boeing.com (Randall E Smith)
Subject: Re: Calling convention: C vs PASCAL
Message-ID: <BzBI1K.5v8@plato.ds.boeing.com>
Organization: Boeing Defense & Space Group
References: <1992Dec11.225015.26304@eng.ufl.edu> <dmurdoch.225.724125846@mast.queensu.ca>
Date: Tue, 15 Dec 1992 20:24:55 GMT
Lines: 38