|
From: | Dave Hansen |
Subject: | Re: [avr-gcc-list] Question about gcc preprocessing and port/pinassignments |
Date: | Fri, 10 Dec 2004 08:09:11 -0500 |
From: David Kelly <address@hidden>
On Dec 9, 2004, at 7:43 PM, Dave Hylands wrote:In the example I showed, a = ( b = 3 ) + 4; we know that a will be assigned 7 and b will be assigned 3. We don't know the order that these assignments will take place in.
It's worse than that. Given b = 3; a = b + 4;we don't know in which order the assignments will take place. Unless 'a' and 'b' are volatile.
A classic example is that the following won't evaluate the same for all C compilers. We know nothing of the order each a++ will be executed. "b" will usually be either 9 or 11, depending on your compiler and its options altho 8 is also possible.a = 2; b = a++ + 3 * a++;
Technically, other answers are possible, like 42, or your hard drive being formatted, launching nuclear missiles, or the proverbial demons flying from your nose.
Practically, because the compiler's optimizer is allowed to assume you aren't breaking the rules (even though it seems obvious it should be able to see that, it isn't required to detect it), you can get some very strange answers numerically. I wouldn't be at all surprised by 12 or 16, for example. And I certainly wouldn't be surprised if 'a' was 3 after the statement executed. I suppose I would be surprised by 42, however...
Regards, -=Dave
[Prev in Thread] | Current Thread | [Next in Thread] |