Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!dogie.macc.wisc.edu!indri!xanth!kremer From: kremer@cs.odu.edu (Lloyd Kremer) Newsgroups: comp.lang.c Subject: Re: printf() problem Summary: C does not specify order of evaluation of function arguments Keywords: C printf Message-ID: <8648@xanth.cs.odu.edu> Date: 26 Apr 89 19:55:40 GMT References: <11657@hodge.UUCP> <89Apr26.092233edt.18850@me.utoronto.ca> Organization: Old Dominion University, Norfolk, Va. Lines: 29 In article <89Apr26.092233edt.18850@me.utoronto.ca> zougas@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!