public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26060] New: A ^= B ^= A ^=B doesn't work if compiled with -g
@ 2006-02-01 9:48 vitaly at siliconds dot com
2006-02-01 10:23 ` [Bug c/26060] " pluto at agmk dot net
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: vitaly at siliconds dot com @ 2006-02-01 9:48 UTC (permalink / raw)
To: gcc-bugs
Following program works differently - if compiled with flag -g or without:
--------------
#include <iostream>
using namespace std;
int main(){
unsigned char a[10];
a[0] = 'A';
a[2] = 'B';
a[0] ^= a[2] ^= a[0] ^= a[2];
cout <<"a0="<<a[0]<<" a2="<<a[2]<<endl;
}
==============================
VITALY:/tmp>g++_4.0.2 -O3 a.cc
VITALY:/tmp>./a.out
a0=B a2=A
VITALY:/tmp>g++_4.0.2 -g a.cc
VITALY:/tmp>./a.out
a0= a2=A
===============================
:/tmp>g++_4.0.2 -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0.2/configure
--prefix=/jer/sys/contrib/linux/gcc-4.0.2_i686/ --with-static-libgcc
--disable-shared -enable-languages=c,c++
Thread model: posix
gcc version 4.0.2
--
Summary: A ^= B ^= A ^=B doesn't work if compiled with -g
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: vitaly at siliconds dot com
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26060
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/26060] A ^= B ^= A ^=B doesn't work if compiled with -g
2006-02-01 9:48 [Bug c/26060] New: A ^= B ^= A ^=B doesn't work if compiled with -g vitaly at siliconds dot com
@ 2006-02-01 10:23 ` pluto at agmk dot net
2006-02-01 10:34 ` schwab at suse dot de
2006-02-01 11:09 ` vitaly at siliconds dot com
2 siblings, 0 replies; 4+ messages in thread
From: pluto at agmk dot net @ 2006-02-01 10:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pluto at agmk dot net 2006-02-01 10:23 -------
It's not a gcc bug. The code relies on the results of intermediate
subexpressions. According to Stroustrup, The C++ Programming Language, section
6.2.2, "The order of evaluation of subexpressions within
an expression is undefined."
You should use sequence points e.g.:
a ^= b, b ^= a, a ^= b;
--
pluto at agmk dot net changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|A ^= B ^= A ^=B doesn't |A ^= B ^= A ^=B doesn't
|work if compiled with -g |work if compiled with -g
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26060
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/26060] A ^= B ^= A ^=B doesn't work if compiled with -g
2006-02-01 9:48 [Bug c/26060] New: A ^= B ^= A ^=B doesn't work if compiled with -g vitaly at siliconds dot com
2006-02-01 10:23 ` [Bug c/26060] " pluto at agmk dot net
@ 2006-02-01 10:34 ` schwab at suse dot de
2006-02-01 11:09 ` vitaly at siliconds dot com
2 siblings, 0 replies; 4+ messages in thread
From: schwab at suse dot de @ 2006-02-01 10:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from schwab at suse dot de 2006-02-01 10:34 -------
*** This bug has been marked as a duplicate of 11751 ***
--
schwab at suse dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26060
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/26060] A ^= B ^= A ^=B doesn't work if compiled with -g
2006-02-01 9:48 [Bug c/26060] New: A ^= B ^= A ^=B doesn't work if compiled with -g vitaly at siliconds dot com
2006-02-01 10:23 ` [Bug c/26060] " pluto at agmk dot net
2006-02-01 10:34 ` schwab at suse dot de
@ 2006-02-01 11:09 ` vitaly at siliconds dot com
2 siblings, 0 replies; 4+ messages in thread
From: vitaly at siliconds dot com @ 2006-02-01 11:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from vitaly at siliconds dot com 2006-02-01 11:08 -------
Thank you very much.
--
vitaly at siliconds dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |VERIFIED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26060
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-02-01 11:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-01 9:48 [Bug c/26060] New: A ^= B ^= A ^=B doesn't work if compiled with -g vitaly at siliconds dot com
2006-02-01 10:23 ` [Bug c/26060] " pluto at agmk dot net
2006-02-01 10:34 ` schwab at suse dot de
2006-02-01 11:09 ` vitaly at siliconds dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).