1 #ifndef CLIB_MACROS_H 2 #define CLIB_MACROS_H 3 4 /* 5 MIN, MAX and ABS macros 6 7 Copyright © 2002 The MorphOS Development Team, All Rights Reserved. 8 */ 9 10 #if defined(__GNUC__) 11 12 #define MIN(a,b) \ 13 ({typeof(a) _a = (a); \ 14 typeof(b) _b = (b); \ 15 _a < _b ? _a : _b; }) 16 17 #define MAX(a,b) \ 18 ({typeof(a) _a = (a); \ 19 typeof(b) _b = (b); \ 20 _a > _b ? _a : _b; }) 21 22 #define ABS(a) \ 23 ({typeof(a) _a = (a); \ 24 _a < 0 ? -_a : _a; }) 25 26 #else /* defined(__GNUC__) */ 27 28 #if defined(__cplusplus) 29 30 #define MIN(a,b) min(a,b) 31 #define MAX(a,b) max(a,b) 32 33 #else /* defined(__cplusplus) */ 34 35 #warning MIN and MAX macros have side-effects 36 #define MIN(a,b) ((a)<(b)?(a):(b)) 37 #define MAX(a,b) ((a)>(b)?(a):(b)) 38 39 #endif /* defined(__cplusplus) */ 40 41 #warning ABS macro has side-effects 42 #define ABS(x) ((x<0)?(-(x)):(x)) 43 44 #endif /* defined(__GNUC__) */ 45 46 #endif /* CLIB_MACROS_H */