swap of variables without tmp

This is a discussion on swap of variables without tmp within the C Programming forums, part of the General Programming Boards category; Code: b ^= a ^= b; I think this is still undefined - you are modifying AND using b in ...

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    b ^= a ^= b;
    I think this is still undefined - you are modifying AND using b in the same statement - how do you know which order it does things? a ^= b first, or b ^= a first?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by matsp View Post
    Code:
    b ^= a ^= b;
    I think this is still undefined - you are modifying AND using b in the same statement - how do you know which order it does things? a ^= b first, or b ^= a first?

    --
    Mats
    I don't think it can do b ^= a at all, can it? Assignment statements have to move right-to-left.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best way to avoid using global variables
    By Canadian0469 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2008, 11:02 AM
  2. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 03:46 PM
  3. Swap two variables with out third variable
    By nkanthikiran in forum C Programming
    Replies: 3
    Last Post: 01-30-2005, 12:33 PM
  4. hwnd and variables in them
    By underthesun in forum Windows Programming
    Replies: 6
    Last Post: 01-16-2005, 05:39 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 01:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21