This article is within the scope of WikiProject C/C++, a collaborative effort to improve the coverage of C/C++ on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
This article is within the scope of WikiProject Java, a collaborative effort to improve the coverage of Java on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
This article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
By definition when operators are overloaded, the ++ has to store its result first and make a copy of the old value, but for built-in types is the compiler not free to use any valid instruction order between sequence points as had been described? I admit I expanded on that section slightly when merging without consulting other sources though.
Of course, half of the point is that for any sensible expression, it doesn't matter what order these different values are updated... but it could make a difference if (for example) p happens to point to the location where its own value (or that of q) is stored, etc.
I'm relativly sure the following paragraph is incorrect.
Consider two functions f() and g(). In C and C++, the + operator is not a sequence point, and therefore in the expression f()+g() it is possible that either f() or g() will be executed first. The comma operator is a sequence point, and therefore in the code f(),g() the order of evaluation is defined (i.e., first f() is called, and then g() is called). The type and value of the whole expression are those of g(); the value of f() is discarded.
According to C99 126.96.36.199 Program execution Example, The function f() is guaranteed to be called before g(). Also on page 74, it also mentions that left associative operators of equal precedence will be executed in left to right order. The function f() will defiantly be called before g(). —Preceding unsigned comment added by 188.8.131.52 (talk) 04:14, 17 February 2009 (UTC)
That is incorrect. Nowhere in C and/or C++ language specifications it says that built-in left-associative operators are executed in left-to-right order. There's no such example in 184.108.40.206 and there's nothing even remotely relevant on page 74 of C99. Please, clarify where you are getting this from.
Why do we care where he gets it from? As you say, it's incorrect. — DAGwyn — Preceding unsigned comment added by 220.127.116.11 (talk) 21:42, 20 June 2011 (UTC)
You're mixing up expression evaluation with operator precedence. The latter only describes how the value of a statement is constructed using fixed, i.e. already evaluated values. Expression evaluation, however, is the process of getting a value from an expression. I.e. "a+b+c" is an expression and each variable is evaluated, i.e. its value is read from memory. In "a+g()+c", a and c are read and g() is called in order to evaluate the expression of g(), i.e. to get its (return) value. In "f()+g()+h()", each function is called and let's assume that the results are 1, 2 and 3. Afterwards the value of the expression is formed by adding "1+2+3" and that is done - as you said - by doing left-associative adding, i.e. first adding 1+2 and then the result is added with 3, i.e. (1+2)+3. The order of the function calls f(), g() and h() , however, is total unspecified.