Newsgroups: | comp.compilers |
From: | daniels@cse.ogi.edu (Scott David Daniels) |
Keywords: | C, Fortran, optimize, design |
Organization: | Oregon Graduate Institute (formerly OGC), Beaverton, OR |
References: | 95-08-067 95-08-163 |
Date: | Thu, 24 Aug 1995 20:48:12 GMT |
I am surprised that nobody has pointed out what I feel
is ``the cause'' for leaving evaluation order (of function
arguments) unspecified:
In K&R C, it must be possible to generate a call to a
function without knowing its declaration. Further,
providing too many arguments to a function is permissible.
On some architectures, arguments are pushed on a stack (which
must be cleaned up at the call site, since that is the
only place where the number of args pushed resides). On
such architectures, only the last value pushed is in a
predictable location (the top of the stack). C compilers on
these machines often push arguments in reverse order (right-
to-left) so that the left-most (or first) argument is the
last one pushed on the stack. For such systems, it is silly
to require evaluation left-to-right; it is much simpler to
evaluate an arg at a time (left-to-right), pushing the value
onto the stack as it is calculated.
On other architectures, there is some concept of a ``call
frame,'' where the function call includes specifying the
base of the argument list. For such machines, a strict
left-to-right evaluation is simplest, since the distinguished
argument to the receiver is the first, rather than the last,
argument pushed on the stack.
Lest anyone think I am inventing architerctures or code
organization, I recently (within the last five years) was asked
to produce a kind of "currying" function for C across a set of
four platfoprms we were using. Although I could produce the
code to incrementally curry on any one of the platforms, some
platforms allowed easy currying of the last argument, while
others allowed only easy currying of the first arg. The upshot
of all of this was that we had to re-architect the code.
-Scott David Daniels
daniels@cse.ogi.edu
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.