Argument Passing in C

William E. Davidsen Jr davidsen at steinmetz.ge.com
Wed Sep 21 02:18:03 AEST 1988


In article <2235 at ssc-vax.UUCP> dmg at ssc-vax.UUCP (David Geary) writes:
	[ discussion about how one C implementation works ]

| Am I thinking correctly?  I've never written a compiler, so I am not real
| sure about this.  Also, I'm a bit confused about what is left up to the
| compiler as far as HOW to implement the passing of variable values.  Does
| the compiler HAVE TO do it this way. Does the compiler have the freedom
| to, say, grow the stack towards the end of memory instead of the beginning?
| Where is all this kind of stuff spelled out?

There is no reason why the compiler even has to use a stack at all. It's
the common way to do it, but some machines have features which make it
inpractical. The VAX has hardware support for other argument passing
mechanisms by pointing the argument pointer to a data block. The
Honeywell machines don't have a hardware stack, and can have any number
of software stacks.

| I am teaching an Advanced C course, and am showing my students how
| to write variadic functions.  I want to make sure that the above is
| correct, and also be prepared to answer the questions in the above
| paragraph.

I hope you're not teaching anything other than varargs... unless they're
writing the varargs package for your C implementation you should be
doing things the portable way.

I've been teaching C since V7, and although I use the stack model as a
conceptual model, I repeat many times that it doesn't have to work that
way, and that you can't assume it does.
-- 
	bill davidsen		(wedu at ge-crd.arpa)
  {uunet | philabs}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list