Click here to Skip to main content
15,892,768 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Increment and Decrement Operators Pin
Richard MacCutchan7-Jan-14 2:48
mveRichard MacCutchan7-Jan-14 2:48 
GeneralRe: Increment and Decrement Operators Pin
Marco Bertschi7-Jan-14 9:41
protectorMarco Bertschi7-Jan-14 9:41 
GeneralRe: Increment and Decrement Operators Pin
Richard MacCutchan7-Jan-14 21:55
mveRichard MacCutchan7-Jan-14 21:55 
GeneralRe: Increment and Decrement Operators Pin
David Crow7-Jan-14 16:43
David Crow7-Jan-14 16:43 
GeneralRe: Increment and Decrement Operators Pin
Ron Beyer7-Jan-14 17:27
professionalRon Beyer7-Jan-14 17:27 
GeneralRe: Increment and Decrement Operators Pin
Suk@nta7-Jan-14 19:27
Suk@nta7-Jan-14 19:27 
GeneralRe: Increment and Decrement Operators Pin
Richard MacCutchan7-Jan-14 21:59
mveRichard MacCutchan7-Jan-14 21:59 
GeneralRe: Increment and Decrement Operators Pin
Stefan_Lang10-Jan-14 2:49
Stefan_Lang10-Jan-14 2:49 
Am I the only one to spot that at least one of the problems in your last line is not related to increment and decrement at all? The operator+ which is invoked here needs to evaluate both of its operands, but it's undefined whether the first or second operand is evaluated first - the compiler may choose to do either!

So, if the compiler evaluates the first operand first, the following happens:
C++
i = 10;
i = i + 1; // pre-increment of the first argument
first_arg = i;
second_arg = i;
i = i + 1; // post-increment of the second argument
result = first_arg + second_arg; // 11 + 11


Now consider the same on the assumption the compiler evaluates the second operand first:
C++
i = 10;
second_arg = i;
i = i + 1; // post-increment of second argument
i = i + 1; // pre-increment of first argument
first_arg = 1;
result = first_arg + second_arg; // 12 + 10


In this case, the results are the same, but that is just by coincidence - if you had used subtraction in stead of addition you'd be in for a surprise!

You may want to check http://en.cppreference.com/w/cpp/language/eval_order[^] for further information regarding both function argument evaluation and increment/decrement.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

GeneralRe: Increment and Decrement Operators Pin
Richard MacCutchan10-Jan-14 3:33
mveRichard MacCutchan10-Jan-14 3:33 
AnswerMessage Closed Pin
7-Jan-14 0:28
Suk@nta7-Jan-14 0:28 
GeneralRe: Increment and Decrement Operators Pin
OriginalGriff8-Jan-14 1:59
mveOriginalGriff8-Jan-14 1:59 
GeneralRe: Increment and Decrement Operators Pin
Suk@nta9-Jan-14 18:17
Suk@nta9-Jan-14 18:17 
GeneralRe: Increment and Decrement Operators Pin
OriginalGriff9-Jan-14 22:10
mveOriginalGriff9-Jan-14 22:10 
GeneralRe: Increment and Decrement Operators Pin
Suk@nta10-Jan-14 3:52
Suk@nta10-Jan-14 3:52 
AnswerRe: Increment and Decrement Operators Pin
Marco Bertschi7-Jan-14 1:31
protectorMarco Bertschi7-Jan-14 1:31 
AnswerRe: Increment and Decrement Operators Pin
tgsb7-Jan-14 20:38
tgsb7-Jan-14 20:38 
GeneralRe: Increment and Decrement Operators Pin
OriginalGriff8-Jan-14 1:56
mveOriginalGriff8-Jan-14 1:56 
GeneralRe: Increment and Decrement Operators Pin
tgsb8-Jan-14 19:43
tgsb8-Jan-14 19:43 
GeneralRe: Increment and Decrement Operators Pin
OriginalGriff8-Jan-14 19:44
mveOriginalGriff8-Jan-14 19:44 
QuestionCTreeCtrl::GetNextSiblingItem never null Pin
dliviu6-Jan-14 1:15
dliviu6-Jan-14 1:15 
AnswerRe: CTreeCtrl::GetNextSiblingItem never null Pin
_Flaviu7-Jan-14 20:24
_Flaviu7-Jan-14 20:24 
GeneralRe: CTreeCtrl::GetNextSiblingItem never null Pin
dliviu8-Jan-14 0:55
dliviu8-Jan-14 0:55 
GeneralRe: CTreeCtrl::GetNextSiblingItem never null Pin
_Flaviu8-Jan-14 1:27
_Flaviu8-Jan-14 1:27 
GeneralRe: CTreeCtrl::GetNextSiblingItem never null Pin
dliviu8-Jan-14 1:36
dliviu8-Jan-14 1:36 
QuestionShort time format Pin
_Flaviu6-Jan-14 0:42
_Flaviu6-Jan-14 0:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.