Thread: swap of variables without tmp

  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,336
    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.

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, 12:02 PM
  2. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 04:46 PM
  3. Swap two variables with out third variable
    By nkanthikiran in forum C Programming
    Replies: 3
    Last Post: 01-30-2005, 01:33 PM
  4. hwnd and variables in them
    By underthesun in forum Windows Programming
    Replies: 6
    Last Post: 01-16-2005, 06:39 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 02:39 PM