a urgent reply needed

Discussion in 'C' started by vignesh1988i, Dec 28, 2009.

  1. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    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
     
  2. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    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              
    
     
  3. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    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 ??????:undecided:undecided
     
  4. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    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"?
     
  5. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    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.......:pleased::pleased: in other compiler it's printing as 7........


    thank u
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice