a urgent reply needed

vignesh1988i's Avatar
Banned
say the output for the following code with explanation how is it implemented inside the compiler : main() { int i=3,j; j=i++ + i++; printf("%d %d",i,j); } thanks in advance
0
Gene Poole's Avatar, Join Date: Nov 2009
Contributor
My compiler (VS2008, debug,x86) implements it thus:

Code:
main() { int i=3,j; j=i++ + i++; printf("%d %d",i,j); }
00063950  push        ebp  
00063951  mov         ebp,esp 
00063953  sub         esp,0D8h 
00063959  push        ebx  
0006395A  push        esi  
0006395B  push        edi  
0006395C  lea         edi,[ebp-0D8h] 
00063962  mov         ecx,36h 
00063967  mov         eax,0CCCCCCCCh 
0006396C  rep stos    dword ptr es:[edi] 
0006396E  mov         dword ptr [i],3 
00063975  mov         eax,dword ptr [i] 
00063978  add         eax,dword ptr [i] 
0006397B  mov         dword ptr [j],eax 
0006397E  mov         ecx,dword ptr [i] 
00063981  add         ecx,1 
00063984  mov         dword ptr [i],ecx 
00063987  mov         edx,dword ptr [i] 
0006398A  add         edx,1 
0006398D  mov         dword ptr [i],edx 
00063990  mov         esi,esp 
00063992  mov         eax,dword ptr [j] 
00063995  push        eax  
00063996  mov         ecx,dword ptr [i] 
00063999  push        ecx  
0006399A  push        offset string "%d %d" (6573Ch) 
0006399F  call        dword ptr [__imp__printf (68374h)] 
000639A5  add         esp,0Ch 
000639A8  cmp         esi,esp 
000639AA  call        @ILT+335(__RTC_CheckEsp) (61154h) 
000639AF  xor         eax,eax 
000639B1  pop         edi  
000639B2  pop         esi  
000639B3  pop         ebx  
000639B4  add         esp,0D8h 
000639BA  cmp         ebp,esp 
000639BC  call        @ILT+335(__RTC_CheckEsp) (61154h) 
000639C1  mov         esp,ebp 
000639C3  pop         ebp  
000639C4  ret
0
vignesh1988i's Avatar
Banned
first thank u for ur effort........ Actually i dunno 8086 assembly programming , now only learning ... so only am not able to appreciate ur program.... can u pl. tell me the implementation more easily from the compiler point of view ??????
0
Gene Poole's Avatar, Join Date: Nov 2009
Contributor
What is it you want to know? You've been told in another thread that expressions of this sort:

Code:
j=i++ + i++;
are undefined and compiler dependent. In the case of this code, it appears that j is assigned i+i (3+3=6) then i is incremented twice (i++; i++; so i is now 5), but not until after the assignment operation.

There's no reason why any sane programmer would ever need to use such an expression.

Why is this "urgent"?
0
vignesh1988i's Avatar
Banned
no no , actually i had a debugging test day before yest... that's why i put urgent.... and u are correct , it's purely compiler dependent ... i too saw today....... in other compiler it's printing as 7........


thank u