public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39121]  New: strange behavior of a chain of operations.
@ 2009-02-06 19:40 nospam at pamies dot cat
  2009-02-06 20:10 ` [Bug c/39121] strange behavior in chained operations pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: nospam at pamies dot cat @ 2009-02-06 19:40 UTC (permalink / raw)
  To: gcc-bugs

#include <stdio.h>

/*
  Why the first swap operation works as expected but
  it does not happen the same with the second one ?
  I guess that it can be due operations within temp values,
  but IMHO swap operation should work in both cases.

  Thanks !
 */

void swap(int *a, int *b) {
    *a ^= *b ^= *a ^= *b;
}

int main() {
    int a = 5;
    int b = 8;
    printf("%d, %d\n", a, b);
    a ^= b ^= a ^= b;
    printf("%d, %d\n", a, b);
    swap(&a, &b);
    printf("%d, %d\n", a, b);
}


-- 
           Summary: strange behavior of a chain of operations.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: nospam at pamies dot cat


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-08-10  3:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-39121-4@http.gcc.gnu.org/bugzilla/>
2015-06-25 18:51 ` [Bug c/39121] strange behavior in chained operations joe.carnuccio at qlogic dot com
2015-06-25 19:10 ` pinskia at gcc dot gnu.org
2015-06-25 19:40 ` joe.carnuccio at qlogic dot com
2015-06-25 20:08 ` manu at gcc dot gnu.org
2015-08-10  3:38 ` frankhb1989 at gmail dot com
2009-02-06 19:40 [Bug c/39121] New: strange behavior of a chain of operations nospam at pamies dot cat
2009-02-06 20:10 ` [Bug c/39121] strange behavior in chained operations pinskia at gcc dot gnu dot org
2009-02-06 21:07 ` nospam at pamies dot cat
2009-02-06 21:22 ` rguenth at gcc dot gnu dot org

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).