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

C / C++ / MFC

 
GeneralRe: Increment and Decrement Operators Pin
Suk@nta7-Jan-14 0:27
Suk@nta7-Jan-14 0:27 
GeneralRe: Increment and Decrement Operators Pin
Richard MacCutchan7-Jan-14 0:35
mveRichard MacCutchan7-Jan-14 0:35 
GeneralRe: Increment and Decrement Operators Pin
Marco Bertschi7-Jan-14 1:27
protectorMarco Bertschi7-Jan-14 1:27 
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 
I'll explain why the behavior is undefined...

This has a lot to do with operator precedence[^], see the ++ as a prefix operator has an equal precedence to the + operator. Its up to the compiler to determine which one to evaluate first, since they are at an equal precedence there is no universal "++(pre) before +".

However, ++ as a postfix operator has a higher precedence than the prefix operator, so for example:

i = 10
result = ++i + i++;

Turns into
result = ++i + 11;

Now, the compiler really doesn't care which one is evaluated first, the + or the ++. Each one is free to implement it as they see fit, so it might be 22 or it might be 23, it depends on which one the programmer handled first.
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 
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 

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.