From: Igor Tandetnik on 19 Jan 2010 13:11 Ulrich Eckhardt <eckhardt(a)satorlaser.com> wrote: > #include <stdio.h> > int g = 0; > void foo(int x) > { > printf("x=%d, g=%d\n", x, g); > } > int main() > { > foo(g++); > } > // output: x=0, g=1 > > Note: I'm not 100% sure if this is a proof, it might actually invoke > implementation-specific behaviour or even undefined behaviour. Looks OK to me. There is a sequence point after all function parameters are evaluated, and before the function's body is entered. All side effects from parameter evaluation must compete by then. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Barry Schwarz on 30 Jan 2010 19:53 On Tue, 19 Jan 2010 00:32:58 -0500, "Chris Saunders" <evas(a)mountaincable.net> wrote: > >Thanks for the reply Scott. Unfortunatly your answer was not clear to me. >Perhaps my question wasn't clear enough. I'll try to be clearer. Is the ++ >performed before or after x is set? I don't think x = mt[mti++] is the same >as x = mt[++mti] is it? In your original example, mti++ is evaluated. The result is the current unmodified value of mti. Then two additional things happen. A value is stored in x and the incremented value is stored in mti. These last two can happen in any order the compiler chooses. In your second example, ++mti is evaluated. The result is the current value of mti+1. Then two additional things happen. A (different) value is stored in x and the incremented value is stored in mti. These last two also can happen in any order the compiler chooses. The pre- and post-fix increment operators do not tell you when the operand is incremented. They only tell you whether the result of the evaluation is the incremented value or not. -- Remove del for email
First
|
Prev
|
Pages: 1 2 Prev: Template compilation Next: Why is CArchive class not derived from Cobject class in MFC |