home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,308 of 33,346   
   Francis Glassborow to PiotrN   
   Re: postfix operator++   
   17 May 12 13:16:45   
   
   39ede19f   
   From: francis.glassborow@btinternet.com   
      
   On 17/05/2012 14:44, PiotrN wrote:   
   > On 17 Maj, 09:13, ravinder thakur  wrote:   
   >> int x = 10;   
   >> x = x++;   
   >>   
   >> I expect value of x to be 10 after the second assignment, however   
   >> its coming out to be 11. Any ideas whats happening ?   
   >>   
   >   
   > I believe this is equivalent to:   
   >   
   > int x = 10;   
   > x = x, ++x;   
   >   
   > So it is obvious, x is 11 after all.   
   >   
   > Consider this:   
   > int x = 10;   
   > int a;   
   > a = x++;   
   >   
   > a is 10 and x is 11   
   > same as for this code:   
   > a = x, ++x;   
   >   
   > HTH,   
   > Piotr   
   >   
   >   
      
   Please note that the explanations people are giving for the result are   
   spurious because the Standard makes no requirements for the   
   consequences of writing twice to the same storage without an   
   intervening sequence point. It is true that almost always executing   
   that statement will result in either x being 10 or x being 11 but it   
   could result in anything including shutting down your computer.   
      
   Francis   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca