Portable C SWAP macro which doesn't require a 'type' argument and doesn't use memcpy
问题 Swap macro's which take a type are fairly well known. #define SWAP(type, a_, b_) do { \ type SWAP, *a = &(a_), *b = &(b_); \ SWAP = *a; \ *a = *b; \ *b = SWAP; \ } while (0) also: Macro SWAP(t,x,y) exchanging two arguments of type t Is it possible to implement this functionality while being... portable (no compiler specific typeof ) without using function calls such as memcpy (which isn't assured to get optimized out, it wasn't in my tests at least ) I came up with a flawed method which uses