diff --git a/src/include/ngspice/macros.h b/src/include/ngspice/macros.h index 47d2886f6..4d2fafd0a 100644 --- a/src/include/ngspice/macros.h +++ b/src/include/ngspice/macros.h @@ -36,7 +36,12 @@ #define ABS(a) ((a) < 0.0 ? -(a) : (a)) #define SGN(a) ((a) < 0.0 ? -(1.0) : (1.0)) #define SIGN(a,b) ( b >= 0 ? (a >= 0 ? a : - a) : (a >= 0 ? - a : a)) -#define SWAP(type, a, b) {type swapx; swapx = a; a = b; b = swapx;} +#define SWAP(type, a, b) \ + do { \ + type SWAP_macro_local = a; \ + a = b; \ + b = SWAP_macro_local; \ + } while(0) #define ABORT() \ diff --git a/src/maths/sparse/spdefs.h b/src/maths/sparse/spdefs.h index 0eaf0b0a1..7efe6a2a8 100644 --- a/src/maths/sparse/spdefs.h +++ b/src/maths/sparse/spdefs.h @@ -78,7 +78,12 @@ #define SQR(a) ((a)*(a)) /* Macro procedure that swaps two entities. */ -#define SWAP(type, a, b) {type swapx; swapx = a; a = b; b = swapx;} +#define SWAP(type, a, b) \ + do { \ + type SWAP_macro_local = a; \ + a = b; \ + b = SWAP_macro_local; \ + } while(0)