Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-10-27 15:18:54 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-27 15:18:54 +0400
commit9fc95bd7ee2aed9d4de7c3c05dfef6597b83a332 (patch)
treea93569a6068e176cd68d859e880a3124da37d7dd /source/blender/blenlib/BLI_utildefines.h
parentec67334e25b92c60f97978ef1bf754b4ba55127e (diff)
use min/max inline functions where MIN2/MAX2 were doing type conversion.
Diffstat (limited to 'source/blender/blenlib/BLI_utildefines.h')
-rw-r--r--source/blender/blenlib/BLI_utildefines.h21
1 files changed, 14 insertions, 7 deletions
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index c27ea7146b5..d905d40d4d9 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -40,15 +40,22 @@
# define TRUE 1
#endif
+/* useful for finding bad use of min/max */
+#if 0
+/* gcc only */
+# define _TYPECHECK(a, b) ((void)(((typeof(a) *)0) == ((typeof(b) *)0)))
+#else
+# define _TYPECHECK(a, b) (void)0
+#endif
/* min/max */
-#define MIN2(x, y) ( (x) < (y) ? (x) : (y) )
-#define MIN3(x, y, z) MIN2(MIN2((x), (y)), (z) )
-#define MIN4(x, y, z, a) MIN2(MIN2((x), (y)), MIN2((z), (a)) )
+#define MIN2(x, y) (_TYPECHECK(x, y), (((x) < (y) ? (x) : (y))))
+#define MIN3(x, y, z) (MIN2(MIN2((x), (y)), (z)))
+#define MIN4(x, y, z, a) (MIN2(MIN2((x), (y)), MIN2((z), (a))))
-#define MAX2(x, y) ( (x) > (y) ? (x) : (y) )
-#define MAX3(x, y, z) MAX2(MAX2((x), (y)), (z) )
-#define MAX4(x, y, z, a) MAX2(MAX2((x), (y)), MAX2((z), (a)) )
+#define MAX2(x, y) (_TYPECHECK(x, y), (((x) > (y) ? (x) : (y))))
+#define MAX3(x, y, z) (MAX2(MAX2((x), (y)), (z)))
+#define MAX4(x, y, z, a) (MAX2(MAX2((x), (y)), MAX2((z), (a))))
#define INIT_MINMAX(min, max) { \
(min)[0] = (min)[1] = (min)[2] = 1.0e30f; \
@@ -109,7 +116,7 @@
#define CHECK_TYPE_INLINE(val, type) \
((void)(((type *)0) != (val)))
-#define SWAP(type, a, b) { \
+#define SWAP(type, a, b) { \
type sw_ap; \
CHECK_TYPE(a, type); \
CHECK_TYPE(b, type); \