Author: Gareth McCaughan
Date: 05:48:41 12/15/01
Go up one level in this thread
On December 15, 2001 at 01:26:16, Dieter Buerssner wrote: [to Dann] > I had written my answer offline, before I had seen, that you gave essentially > the same answer already. Actually your answers aren't "essentially the same" unless I've misunderstood at least one of them. Dann was saying: "The compiler ought to do things in a consistent order here, and the vendor is breaking the rules if it doesn't". You were saying "The order in which things happen here is undefined". You were right and Dann (to my surprise, since he's normally very reliable on these matters!) was wrong. a^b^c has to be parsed as (a^b)^c ... errm, or maybe I mean a^(b^c); it doesn't matter here ... but that has nothing to do with the order in which the subexpressions actually get evaluated. There are no sequence points in the expression, so the compiler has the freedom to do as it pleases with evaluation order provided it gives the right answer. Since ^ is associative (note to any non-C-programmers reading this: that's xor, not exponent!) it doesn't make any difference whether it groups left or right (which is why I can't remember which way, if either, is specified); but in any case that doesn't make any difference to what order the compiler's allowed to do the evaluations in. So Paul's compiler is perfectly within its rights to do things differently in debug and release mode. It's possible that Dann's been misled by the references in the C FAQ to "just before a function call". That doesn't mean that if you say a()+b() it has to evaluate a() before b(). It just means that when you do a function call, all the argument expressions (and the expression that determines what function to call, too!) have to be completely evaluated -- side-effects and all -- before the function is actually called. It's very unclearly expressed in the standard, unfortunately. -- g
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.