Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: stack quirk? Message-ID: <359@taumet.com> Date: 28 Jul 90 22:18:46 GMT References: <4047@pikes.Colorado.EDU> <31530012@hpcvia.CV.HP.COM> Organization: Taumetric Corporation, San Diego Lines: 26 brianh@hpcvia.CV.HP.COM (brian_helterline) writes: |>printf("\n%d %d\n", ++i, ++i); |> etc | The output you got should is correct. The arguments to | printf() [or any function] are pushed on to the stack | right to left so they are in the correct order for | printf() to pop them off when needed. If you evaluate | each expression above right-to-left, you will "expect" | exactly what the output was. There is no guarantee in what order ++i and i++ will be evaluated, nor whether the incremented values will be stored before or after the second of the two is evaluated. Consequently, there is no way to predict what the output will be. The ANSI C standard explicitly says that you cannot count on when the "side effects" will take place, except that they will be complete before the function is called. C texts warn (or should warn) about modifying a variable which is referenced more than once in the same expression. Such code is often not warned-about by compilers, and may produce surprisingly different results on different systems. -- Steve Clamage, TauMetric Corp, steve@taumet.com