Click here to Skip to main content
15,888,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: what about x = x++; ? Pin
Chris Losinger15-Sep-05 6:52
professionalChris Losinger15-Sep-05 6:52 
AnswerRe: what about x = x++; ? Pin
David Crow15-Sep-05 6:37
David Crow15-Sep-05 6:37 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 6:55
bugDanny15-Sep-05 6:55 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 7:22
David Crow15-Sep-05 7:22 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 7:33
bugDanny15-Sep-05 7:33 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 8:01
David Crow15-Sep-05 8:01 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 8:08
bugDanny15-Sep-05 8:08 
GeneralRe: what about x = x++; ? Pin
ky_rerun15-Sep-05 9:14
ky_rerun15-Sep-05 9:14 
too add to the confusion.
8: int x = 1;
00401788 mov dword ptr [ebp-4],1
9: int y = 2;
0040178F mov dword ptr [ebp-8],2
10: int z = 0;
00401796 mov dword ptr [ebp-0Ch],0
11: z = y++, y = x++ ;
0040179D mov eax,dword ptr [ebp-8] #Set eax = to the value of X = 1
004017A0 mov dword ptr [ebp-0Ch],eax #Set Y = EAX = 1
004017A3 mov ecx,dword ptr [ebp-8] #Move vlaue of X to ECX
004017A6 add ecx,1 #Add 1 to ECX
004017A9 mov dword ptr [ebp-8],ecx #Move NewValue to Y = 2
004017AC mov edx,dword ptr [ebp-4] #Move X to EDX = 1
004017AF mov dword ptr [ebp-8],edx #Move EDX to Y = 1
004017B2 mov eax,dword ptr [ebp-4] #Move X to EAX
004017B5 add eax,1 #increment
004017B8 mov dword ptr [ebp-4],eax #finaly Reset the value of X
Sleepy | :zzz:
out put Z=2 Y=1 X=2
OMG | :OMG:
The increment always happens last.

When used in an expression the compiler takes the value and sticks it in assembly after the rest of the statement has been compiled it does the increment.


a programmer traped in a thugs body
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 9:22
David Crow15-Sep-05 9:22 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 2:51
bugDanny16-Sep-05 2:51 
AnswerRe: what about x = x++; ? Pin
Joaquín M López Muñoz15-Sep-05 6:51
Joaquín M López Muñoz15-Sep-05 6:51 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 7:23
bugDanny15-Sep-05 7:23 
GeneralRe: what about x = x++; ? Pin
Joaquín M López Muñoz16-Sep-05 5:00
Joaquín M López Muñoz16-Sep-05 5:00 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 6:45
bugDanny16-Sep-05 6:45 
GeneralRe: what about x = x++; ? Pin
Joaquín M López Muñoz16-Sep-05 7:05
Joaquín M López Muñoz16-Sep-05 7:05 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 7:41
bugDanny16-Sep-05 7:41 
AnswerRe: what about x = x++; ? Pin
Anonymous15-Sep-05 8:30
Anonymous15-Sep-05 8:30 
GeneralRe: what about x = x++; ? Pin
Anonymous15-Sep-05 8:38
Anonymous15-Sep-05 8:38 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 8:57
bugDanny15-Sep-05 8:57 
GeneralRe: what about x = x++; ? Pin
Chris Losinger15-Sep-05 8:59
professionalChris Losinger15-Sep-05 8:59 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 9:05
bugDanny15-Sep-05 9:05 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 9:32
David Crow15-Sep-05 9:32 
GeneralRe: what about x = x++; ? Pin
pesho293215-Sep-05 21:02
pesho293215-Sep-05 21:02 
GeneralRe: what about x = x++; ? Pin
David Crow16-Sep-05 2:15
David Crow16-Sep-05 2:15 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 3:15
bugDanny16-Sep-05 3:15 

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.