We’re rewarding the question askers & reputations are being recalculated! Read more.

 4 edited body edited Jun 22 '15 at 5:20 Basile Starynkevitch 29.3k55 gold badges7070 silver badges109109 bronze badges You probably should use a macro or a function `MAX` giving the maximum of two numbers. Then you just want: `````` status = MAX(a,MAX(b,c)); `````` You might have defined `````` #define MAX(X,Y) (((X)>(Y))?(X):(Y)) `````` but be cautious -notably about side effects- when using macros (since `MAX(i++,j--)` would behave strangely) So better define a function `````` static inline int max2ints(int x, int y) { return (x>y)?x:y; } `````` and use it (or at least `#define MAX(X,Y) max2ints((X),(Y))` ....) If you need to understand the origin of the MAX you might have a long macro like `#define COMPUTE_MAX_WITH_CAUSE(Status,Result,X,Y,Z)` which is a long `do{` ... `}while(0)` macro, perhaps ``````#define COMPUTE_MAX_WITH_CAUSE(Status,Result,X,Y,Z) do { \ int x= (X), y= (Y), z=(Z); \ if (x > y && y > z) \ { Status = MOSTLY_FIRST; Result = x; } \ else if (y > x && y > z) \ { Status = MOSTLY_SECOND; Result = y; } \ else if (z > x && z > y) \ { Status = MOSTLY_THIRD; Result = z; } \ /* etc */ \ else { Status = UNKNOWN; Result = ... } \ } while(0) `````` Then you could invoke `COMPUTE_MAX_WITH_CAUSE(status,res,a,b,c)` at several places. It is a bigbit ugly. I defined local variables `x`, `y`, `z` to lower bad side effects.... You probably should use a macro or a function `MAX` giving the maximum of two numbers. Then you just want: `````` status = MAX(a,MAX(b,c)); `````` You might have defined `````` #define MAX(X,Y) (((X)>(Y))?(X):(Y)) `````` but be cautious -notably about side effects- when using macros (since `MAX(i++,j--)` would behave strangely) So better define a function `````` static inline int max2ints(int x, int y) { return (x>y)?x:y; } `````` and use it (or at least `#define MAX(X,Y) max2ints((X),(Y))` ....) If you need to understand the origin of the MAX you might have a long macro like `#define COMPUTE_MAX_WITH_CAUSE(Status,Result,X,Y,Z)` which is a long `do{` ... `}while(0)` macro, perhaps ``````#define COMPUTE_MAX_WITH_CAUSE(Status,Result,X,Y,Z) do { \ int x= (X), y= (Y), z=(Z); \ if (x > y && y > z) \ { Status = MOSTLY_FIRST; Result = x; } \ else if (y > x && y > z) \ { Status = MOSTLY_SECOND; Result = y; } \ else if (z > x && z > y) \ { Status = MOSTLY_THIRD; Result = z; } \ /* etc */ \ else { Status = UNKNOWN; Result = ... } \ } while(0) `````` Then you could invoke `COMPUTE_MAX_WITH_CAUSE(status,res,a,b,c)` at several places. It is a big ugly. I defined local variables `x`, `y`, `z` to lower bad side effects.... You probably should use a macro or a function `MAX` giving the maximum of two numbers. Then you just want: `````` status = MAX(a,MAX(b,c)); `````` You might have defined `````` #define MAX(X,Y) (((X)>(Y))?(X):(Y)) `````` but be cautious -notably about side effects- when using macros (since `MAX(i++,j--)` would behave strangely) So better define a function `````` static inline int max2ints(int x, int y) { return (x>y)?x:y; } `````` and use it (or at least `#define MAX(X,Y) max2ints((X),(Y))` ....) If you need to understand the origin of the MAX you might have a long macro like `#define COMPUTE_MAX_WITH_CAUSE(Status,Result,X,Y,Z)` which is a long `do{` ... `}while(0)` macro, perhaps ``````#define COMPUTE_MAX_WITH_CAUSE(Status,Result,X,Y,Z) do { \ int x= (X), y= (Y), z=(Z); \ if (x > y && y > z) \ { Status = MOSTLY_FIRST; Result = x; } \ else if (y > x && y > z) \ { Status = MOSTLY_SECOND; Result = y; } \ else if (z > x && z > y) \ { Status = MOSTLY_THIRD; Result = z; } \ /* etc */ \ else { Status = UNKNOWN; Result = ... } \ } while(0) `````` Then you could invoke `COMPUTE_MAX_WITH_CAUSE(status,res,a,b,c)` at several places. It is a bit ugly. I defined local variables `x`, `y`, `z` to lower bad side effects.... 3 added 186 characters in body edited Jun 22 '15 at 5:13 Basile Starynkevitch 29.3k55 gold badges7070 silver badges109109 bronze badges You probably should use a macro or a function `MAX` giving the maximum of two numbers. Then you just want: `````` status = MAX(a,MAX(b,c)); `````` You might have defined `````` #define MAX(X,Y) (((X)>(Y))?(X):(Y)) `````` but be cautious -notably about side effects- when using macros (since `MAX(i++,j--)` would behave strangely) So better define a function `````` static inline int max2ints(int x, int y) { return (x>y)?x:y; } `````` and use it (or at least `#define MAX(X,Y) max2ints((X),(Y))` ....) If you need to understand the origin of the MAX you might have a long macro like `#define COMPUTE_MAX_WITH_CAUSE(CauseStatus,Result,X,Y,Z)` which is a long `do{` ... `}while(0)` macro, perhaps ``````#define COMPUTE_MAX_WITH_CAUSE(Status,Result,X,Y,Z) do { \ int x= (X), y= (Y), z=(Z); \ if (x > y && y > z) \ { Status = MOSTLY_FIRST; Result = x; } \ else if (y > x && y > z) \ { Status = MOSTLY_SECOND; Result = y; } \ else if (z > x && z > y) \ { Status = MOSTLY_THIRD; Result = z; } \ /* etc */ \ else { Status = UNKNOWN; Result = ... } \ } while(0) `````` Then you could invoke `COMPUTE_MAX_WITH_CAUSE(status,res,a,b,c)` at several places. It is a big ugly. I defined local variables `x`, `y`, `z` to lower bad side effects.... You probably should use a macro or a function `MAX` giving the maximum of two numbers. Then you just want: `````` status = MAX(a,MAX(b,c)); `````` You might have defined `````` #define MAX(X,Y) (((X)>(Y))?(X):(Y)) `````` but be cautious -notably about side effects- when using macros (since `MAX(i++,j--)` would behave strangely) So better define a function `````` static inline int max2ints(int x, int y) { return (x>y)?x:y; } `````` and use it (or at least `#define MAX(X,Y) max2ints((X),(Y))` ....) If you need to understand the origin of the MAX you might have a long macro like `#define COMPUTE_MAX_WITH_CAUSE(Cause,Result,X,Y,Z)` which is a long `do{` ... `}while(0)` macro. You probably should use a macro or a function `MAX` giving the maximum of two numbers. Then you just want: `````` status = MAX(a,MAX(b,c)); `````` You might have defined `````` #define MAX(X,Y) (((X)>(Y))?(X):(Y)) `````` but be cautious -notably about side effects- when using macros (since `MAX(i++,j--)` would behave strangely) So better define a function `````` static inline int max2ints(int x, int y) { return (x>y)?x:y; } `````` and use it (or at least `#define MAX(X,Y) max2ints((X),(Y))` ....) If you need to understand the origin of the MAX you might have a long macro like `#define COMPUTE_MAX_WITH_CAUSE(Status,Result,X,Y,Z)` which is a long `do{` ... `}while(0)` macro, perhaps ``````#define COMPUTE_MAX_WITH_CAUSE(Status,Result,X,Y,Z) do { \ int x= (X), y= (Y), z=(Z); \ if (x > y && y > z) \ { Status = MOSTLY_FIRST; Result = x; } \ else if (y > x && y > z) \ { Status = MOSTLY_SECOND; Result = y; } \ else if (z > x && z > y) \ { Status = MOSTLY_THIRD; Result = z; } \ /* etc */ \ else { Status = UNKNOWN; Result = ... } \ } while(0) `````` Then you could invoke `COMPUTE_MAX_WITH_CAUSE(status,res,a,b,c)` at several places. It is a big ugly. I defined local variables `x`, `y`, `z` to lower bad side effects.... 2 added 186 characters in body edited Jun 22 '15 at 5:07 Basile Starynkevitch 29.3k55 gold badges7070 silver badges109109 bronze badges You probably should use a macro or a function `MAX` giving the maximum of two numbers. Then you just want: `````` status = MAX(a,MAX(b,c)); `````` You might have defined `````` #define MAX(X,Y) (((X)>(Y))?(X):(Y)) `````` but be cautious -notably about side effects- when using macros (since `MAX(i++,j--)` would behave strangely) So better define a function `````` static inline int max2ints(int x, int y) { return (x>y)?x:y; } `````` and use it (or at least `#define MAX(X,Y) max2ints((X),(Y))` ....) If you need to understand the origin of the MAX you might have a long macro like `#define COMPUTE_MAX_WITH_CAUSE(Cause,Result,X,Y,Z)` which is a long `do{` ... `}while(0)` macro. You probably should use a macro or a function `MAX` giving the maximum of two numbers. Then you just want: `````` status = MAX(a,MAX(b,c)); `````` You might have defined `````` #define MAX(X,Y) (((X)>(Y))?(X):(Y)) `````` but be cautious -notably about side effects- when using macros (since `MAX(i++,j--)` would behave strangely) So better define a function `````` static inline int max2ints(int x, int y) { return (x>y)?x:y; } `````` and use it (or at least `#define MAX(X,Y) max2ints((X),(Y))` ....) You probably should use a macro or a function `MAX` giving the maximum of two numbers. Then you just want: `````` status = MAX(a,MAX(b,c)); `````` You might have defined `````` #define MAX(X,Y) (((X)>(Y))?(X):(Y)) `````` but be cautious -notably about side effects- when using macros (since `MAX(i++,j--)` would behave strangely) So better define a function `````` static inline int max2ints(int x, int y) { return (x>y)?x:y; } `````` and use it (or at least `#define MAX(X,Y) max2ints((X),(Y))` ....) If you need to understand the origin of the MAX you might have a long macro like `#define COMPUTE_MAX_WITH_CAUSE(Cause,Result,X,Y,Z)` which is a long `do{` ... `}while(0)` macro. 1 answered Jun 22 '15 at 4:58 Basile Starynkevitch 29.3k55 gold badges7070 silver badges109109 bronze badges