[Bug c++/22248] New: Incorrect work with multiple assigment.

algorithmus at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Jun 30 13:03:00 GMT 2005


hi!

I have a problem with multiply assigment at 
i386-portbld-freebsd5.4
gcc version 4.0.1 20050609 (prerelease) [FreeBSD]

and the same problem in DJGPP with gcc 4.0.0

I've compiled my cpp file with this command line:
g++40 new.cpp

---new.cpp----
#include<cstdio>

#define swap(a,b) a^=b^=a^=b

const int N = 2;
int a[N];

int main()
{
        for(int i=0;i<N;i++) a[i] = i;
        for(int i=0;i<N/2;i++) swap(a[i],a[N-i-1]);
        for(int i=0;i<N;i++) printf("%d ",a[i]);
        printf("\n");
        return 0;
}
-------

This program simply makes 2-element array: a[0] = 0 a[1] = 1;
After that it uses macros swap(a[0],a[1]) to swap these elements.

After swaping program makes a[0] = 0 a[1] = 0 that's not correct.

Actually, if you compile this program with -O2 key: g++40 -O2 new.cpp
program will work fine and make a[0] = 1 a[1] = 0;

The same situation(correct work) will be if you use older gcc 3.x compiler.

I've done several experements and I guess that something wrong causes after last
assigment.

-- 
           Summary: Incorrect work with multiple assigment.
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: algorithmus at gmail dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22248



More information about the Gcc-bugs mailing list