On Mon, 2006-12-11 at 11:06 +0300, XXX XXX wrote:
> Dear Sirs,
> 
> I use gcc 3.4.5 and received following incorrect result in the program.
> On the gcc site exist report about incorrect behavior of ++ operator but not 
> this situation. I hope that it will be usefull.
> 
> I have developed some stupid code to show the problem:


>       *str++ = toupper(*str);

This is not a bug.  

Please read:
http://gcc.gnu.org/bugs.html#nonbugs_c

Increment/decrement operator (++/--) not working as expected - a problem
with many variations.
        
        The following expressions have unpredictable results:
        
                x[i]=++i
                foo(i,++i)
                i*(++i)                 /* special case with foo=="operator*" */
                std::cout << i << ++i   /* foo(foo(std::cout,i),++i)          */
        
        since the i without increment can be evaluated before or after
        ++i.
        
        The C and C++ standards have the notion of "sequence points".
        Everything that happens between two sequence points happens in
        an unspecified order, but it has to happen after the first and
        before the second sequence point. The end of a statement and a
        function call are examples for sequence points, whereas
        assignments and the comma between function arguments are not.
        
        Modifying a value twice between two sequence points as shown in
        the following examples is even worse:
        
                i=++i
                foo(++i,++i)
                (++i)*(++i)               /* special case with foo=="operator*" 
*/
                std::cout << ++i << ++i   /* foo(foo(std::cout,++i),++i)        
*/
        
        This leads to undefined behavior (i.e. the compiler can do
        anything).
        
        
        --Pinski

Reply via email to