Re: Order of argument evaluation in C++, etc.

daniels@cse.ogi.edu (Scott David Daniels)
Thu, 24 Aug 1995 20:48:12 GMT

          From comp.compilers

Related articles
[36 earlier articles]
Re: Order of argument evaluation in C++, etc. bill@amber.ssd.hcsc.com (1995-08-21)
Re: Order of argument evaluation in C++, etc. burley@gnu.ai.mit.edu (1995-08-23)
Re: Order of argument evaluation in C++, etc. jthill@netcom.com (1995-08-24)
Re: Order of argument evaluation in C++, etc. hbaker@netcom.com (1995-08-23)
Re: Order of argument evaluation in C++, etc. way@cis.udel.edu (Thomas Way) (1995-08-23)
Re: Order of argument evaluation in C++, etc. jmccarty@spdmail.spd.dsccc.com (1995-08-24)
Re: Order of argument evaluation in C++, etc. daniels@cse.ogi.edu (1995-08-24)
Re: Order of argument evaluation in C++, etc. pardo@cs.washington.edu (1995-08-25)
Re: Order of argument evaluation in C++, etc. hbaker@netcom.com (1995-08-25)
Re: Order of argument evaluation in C++, etc. jan@neuroinformatik.ruhr-uni-bochum.de (1995-08-25)
Re: Order of argument evaluation in C++, etc. stefan.monnier@epfl.ch (Stefan Monnier) (1995-08-28)
Re: Order of argument evaluation in C++, etc. chase@centerline.com (1995-08-28)
Re: Order of argument evaluation in C++, etc. hbaker@netcom.com (1995-08-30)
| List of all articles for this month |

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
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.