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,327 of 33,346    |
|    Ike Naar to rado    |
|    Re: postfix operator++    |
|    22 May 12 20:59:03    |
   
   f29e377d   
   From: ike@sverige.freeshell.org   
      
   On 2012-05-22, rado wrote:   
   >> You have invoked undefined behaviour because your assignment   
   >> statement modifies x twice without an intervening sequence   
   >> point. This is always a no no in C and C++ for built-in types. The   
   >> same rule applies to struct/class types except that in most   
   >> instances where it looks as this has been done (2 modifications to   
   >> same memory between sequence points) there are some hidden sequence   
   >> points because overloaded operators are actually function calls.   
   >   
   > I wonder why decent compilers don't issue a warning in such cases. Or   
   > maybe they do. Does anybody know?   
   > -- Radoslav Getov   
      
   $ cat a.c   
   int main(void)   
   {   
    int x = 10;   
    x = x++;   
    return 0;   
   }   
   $ gcc --version   
   gcc (GCC) 4.1.2 20061021 prerelease (NetBSD nb3 20061125)   
   Copyright (C) 2006 Free Software Foundation, Inc.   
   This is free software; see the source for copying conditions. There is NO   
   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   
   $ gcc -Wall a.c   
   a.c: In function 'main':   
   a.c:4: warning: operation on 'x' may be undefined   
      
      
   --   
    [ 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