[comp.sys.mac.programmer] The Joy of C Calling Conventions

jnh@ecemwl.ncsu.edu (Joseph N. Hall) (09/16/89)

Is there any particular reason why MPW and THINK C have different calling
conventions?

I can understand that MPW ought to put ints (which are 32 bits in MPW) and
things coerced to ints (chars and shorts w/o prototypes) onto the stack as
longwords.  I don't really understand why, though, the folks at Apple don't
allow for words to be pushed on the stack when there is a word-length
argument, with a prototype, that is to be passed ...

The MPW register-based convention for returning float/double/extended is weird,
but at least it's reentrant.  I guess the folks at Symantec thought it was
TOO weird, though, so THINK C returns doubles like structures.

The upshot of this is that you need to write glue to call fp routines
written in MPW C from THINK C.  I would assume that if you are going the
other way, you ought to be able to force MPW C to use THINK C's conventions
by declaring the interface (in MPW) like :

	typedef struct {
		double val
	} fstruct;

	extern fstruct think_c_funct_returning_double (fstruct *double_arg)

... but, lacking a copy of MPW C, I haven't tried this.

You also need to coerce ints to longs before calling MPW C routines from
THINK C.

It's nice that the Pascal conventions are the same between both dialects
(guess they pretty much have to be).  It's unfortunate that THINK didn't
likewise adopt the MPW C conventions -- or so it seems to me.

Anyone have any experience with this, additional comments, etc.?

v   v sssss|| joseph hall                      || 4116 Brewster Drive
 v v s   s || jnh@ecemwl.ncsu.edu (Internet)   || Raleigh, NC  27606
  v   sss  || SP Software/CAD Tool Developer, Mac Hacker and Keyboardist
-----------|| Disclaimer: NCSU may not share my views, but is welcome to.