diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-03-30 08:02:24 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-03-30 08:04:20 +0400 |
commit | c16bd951cdff8d9dd4ba44e4634cb284c6f09342 (patch) | |
tree | de4f0af701a6516ac803e002038baeb7f61b13ec /source/blender/blenlib/BLI_utildefines.h | |
parent | 0782187979b67a743fe612d7404fe5698a4a7f24 (diff) |
Enable GCC pedantic warnings with strict flags,
also modify MIN/MAX macros to prevent shadowing.
Diffstat (limited to 'source/blender/blenlib/BLI_utildefines.h')
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index bb1b3a368f0..46553ccc0fc 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -50,26 +50,42 @@ /* min/max */ #if defined(__GNUC__) || defined(__clang__) -#define MIN2(x, y) ({ \ - typeof(x) x_ = (x); \ - typeof(y) y_ = (y); \ - ((x_) < (y_) ? (x_) : (y_)); }) +#define MIN2(a, b) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); \ + ((a_) < (b_) ? (a_) : (b_)); }) -#define MAX2(x, y) ({ \ - typeof(x) x_ = (x); \ - typeof(y) y_ = (y); \ - ((x_) > (y_) ? (x_) : (y_)); }) +#define MAX2(a, b) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); \ + ((a_) > (b_) ? (a_) : (b_)); }) + +#define MIN3(a, b, c) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); typeof(c) c_ = (c); \ + ((a_ < b_) ? ((a_ < c_) ? a_ : c_) : ((b_ < c_) ? b_ : c_)); }) + +#define MAX3(a, b, c) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); typeof(c) c_ = (c); \ + ((a_ > b_) ? ((a_ > c_) ? a_ : c_) : ((b_ > c_) ? b_ : c_)); }) + +#define MIN4(a, b, c, d) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); typeof(c) c_ = (c); typeof(d) d_ = (d); \ + ((a_ < b_) ? ((a_ < c_) ? ((a_ < d_) ? a_ : d_) : ((c_ < d_) ? c_ : d_)) : \ + ((b_ < c_) ? ((b_ < d_) ? b_ : d_) : ((c_ < d_) ? c_ : d_))); }) + +#define MAX4(a, b, c, d) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); typeof(c) c_ = (c); typeof(d) d_ = (d); \ + ((a_ > b_) ? ((a_ > c_) ? ((a_ > d_) ? a_ : d_) : ((c_ > d_) ? c_ : d_)) : \ + ((b_ > c_) ? ((b_ > d_) ? b_ : d_) : ((c_ > d_) ? c_ : d_))); }) #else -#define MIN2(x, y) ((x) < (y) ? (x) : (y)) -#define MAX2(x, y) ((x) > (y) ? (x) : (y)) -#endif +#define MIN2(a, b) ((a) < (b) ? (a) : (b)) +#define MAX2(a, b) ((a) > (b) ? (a) : (b)) -#define MIN3(x, y, z) (MIN2(MIN2((x), (y)), (z))) -#define MIN4(x, y, z, a) (MIN2(MIN2((x), (y)), MIN2((z), (a)))) +#define MIN3(a, b, c) (MIN2(MIN2((a), (b)), (c))) +#define MIN4(a, b, c, d) (MIN2(MIN2((a), (b)), MIN2((c), (d)))) -#define MAX3(x, y, z) (MAX2(MAX2((x), (y)), (z))) -#define MAX4(x, y, z, a) (MAX2(MAX2((x), (y)), MAX2((z), (a)))) +#define MAX3(a, b, c) (MAX2(MAX2((a), (b)), (c))) +#define MAX4(a, b, c, d) (MAX2(MAX2((a), (b)), MAX2((c), (d)))) +#endif /* min/max that return a value of our choice */ #define MAX3_PAIR(cmp_a, cmp_b, cmp_c, ret_a, ret_b, ret_c) \ |