Skip to content

Instantly share code, notes, and snippets.

@zodiac1111
Last active August 29, 2015 14:05
Show Gist options
  • Save zodiac1111/a5f49a84849408757fe1 to your computer and use it in GitHub Desktop.
Save zodiac1111/a5f49a84849408757fe1 to your computer and use it in GitHub Desktop.
swap两个数,一种类型无关.宏, 来自 kernel.h
#define swap(a, b) \
do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
/// 临时变量名字,
/// from http://stackoverflow.com/questions/3982348/implement-generic-swap-macro-in-c
#define swap(x, y) \
do { typeof(x) temp##x##y = x; x = y; y = temp##x##y; } while (0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment