printf() problem

Lloyd Kremer kremer at cs.odu.edu
Thu Apr 27 05:55:40 AEST 1989


In article <89Apr26.092233edt.18850 at me.utoronto.ca> zougas at me.utoronto.ca
("Athanasios(Tom) Zougas") writes:

>C puts its function parameters on the stack in "reverse" order, i.e.
>the last item is on top
>
>It would happen in any C.


It's not C that specifies this behavior.  C has never specified any order
of evaluation for function arguments.  C does not even presume the existence
of a last-in-first-out stack onto which arguments could be pushed.  Some
implementations pass args in registers or through a static area reserved for
the purpose.  Some mix register passing and stack passing.

Even in fully stack-based implementations where reverse ordering is the norm,
it cannot be assumed in all cases.  Vagaries of code generation or, more
likely, subsequent optimization, can change the order of evaluation in specific
cases.

The correct solution is unchanged since the early days of C: do not assume
anything regarding the order of evaluation of function arguments.

-- 
					Lloyd Kremer
					Brooks Financial Systems
					...!uunet!xanth!brooks!lloyd
					Have terminal...will hack!



More information about the Comp.lang.c mailing list