Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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)
deleted 114 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192

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)
edited body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192

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)

added 128 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192
Loading
added 342 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192
Loading
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192
Loading
lang-c

AltStyle によって変換されたページ (->オリジナル) /