If you are using GCC, we can use the typeof()
(C99) keyword to get rid of one of the arguments. Also, add a do-while
so the macro to be used in contexts where it would otherwise be problematic add a do-while
so the macro to be used in contexts where it would otherwise be problematic.
#define SWAP(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
You could also use an exclusive-or (^=
) to get rid of that temporary variable, but that only works for integers.
#define SWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
If you are using GCC, we can use the typeof()
(C99) keyword to get rid of one of the arguments. Also, add a do-while
so the macro to be used in contexts where it would otherwise be problematic.
#define SWAP(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
You could also use an exclusive-or (^=
) to get rid of that temporary variable, but that only works for integers.
#define SWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
If you are using GCC, we can use the typeof()
(C99) keyword to get rid of one of the arguments. Also, add a do-while
so the macro to be used in contexts where it would otherwise be problematic.
#define SWAP(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
You could also use an exclusive-or (^=
) to get rid of that temporary variable, but that only works for integers.
#define SWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
If you are using GCC, we can use the typeof()
keyword(1C99) keyword to get rid of one of the arguments. Also, add a do-while
so the macro to be used in contexts where it would otherwise be problematic.
#define SWAP(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
You could also use an exclusive-or (^=
) to get rid of that temporary variable, but that only works for integers.
#define SWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
(1): requires use of the C99 standard (which is the lowest standard you should be using IMO)
If you are using GCC, we can use the typeof()
keyword(1) to get rid of one of the arguments. Also, add a do-while
so the macro to be used in contexts where it would otherwise be problematic.
#define SWAP(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
You could also use an exclusive-or (^=
) to get rid of that temporary variable, but that only works for integers.
#define SWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
(1): requires use of the C99 standard (which is the lowest standard you should be using IMO)
If you are using GCC, we can use the typeof()
(C99) keyword to get rid of one of the arguments. Also, add a do-while
so the macro to be used in contexts where it would otherwise be problematic.
#define SWAP(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
You could also use an exclusive-or (^=
) to get rid of that temporary variable, but that only works for integers.
#define SWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
If you are using gccGCC, we can use the typeof()
keyword(1) to get rid of one of the arguments. Also, add a do-while
so the macro to be used in contexts where it would otherwise be problematic.
#define swapSWAP(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
You could also use an exclusive-or (^=
) to get rid of that temporary variable, but that only works for integers.
#define swapSWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
(1): requires use of the C99 standard (which is the lowest standard you should be using IMO)
If you are using gcc, we can use the typeof()
keyword(1) to get rid of one of the arguments. Also, add a do-while
so the macro to be used in contexts where it would otherwise be problematic.
#define swap(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
You could also use an exclusive-or (^=
) to get rid of that temporary variable, but that only works for integers.
#define swap(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
(1): requires use of the C99 standard (which is the lowest standard you should be using IMO)
If you are using GCC, we can use the typeof()
keyword(1) to get rid of one of the arguments. Also, add a do-while
so the macro to be used in contexts where it would otherwise be problematic.
#define SWAP(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
You could also use an exclusive-or (^=
) to get rid of that temporary variable, but that only works for integers.
#define SWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
(1): requires use of the C99 standard (which is the lowest standard you should be using IMO)