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>2014-09-25 07:05:42 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-09-25 07:07:17 +0400
commit21462410eef2ad8c5b31aa5796a8319b54872c6c (patch)
tree54479050503a3745dfcbc13bcb1de84dfe01d466 /source/blender/blenlib/BLI_compiler_typecheck.h
parent6f2f80887b10f6a704a7394f0580e6ee39ea611d (diff)
Move typecheck macros into own header
Diffstat (limited to 'source/blender/blenlib/BLI_compiler_typecheck.h')
-rw-r--r--source/blender/blenlib/BLI_compiler_typecheck.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_compiler_typecheck.h b/source/blender/blenlib/BLI_compiler_typecheck.h
new file mode 100644
index 00000000000..93dcc6ee866
--- /dev/null
+++ b/source/blender/blenlib/BLI_compiler_typecheck.h
@@ -0,0 +1,74 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_COMPILER_TYPECHECK_H__
+#define __BLI_COMPILER_TYPECHECK_H__
+
+/** \file BLI_compiler_typecheck.h
+ * \ingroup bli
+ *
+ * Type checking macros (often used to ensure valid use of macro args).
+ * These depend on compiler extensions and c11 in some cases.
+ */
+
+/* Causes warning:
+ * incompatible types when assigning to type 'Foo' from type 'Bar'
+ * ... the compiler optimizes away the temp var */
+#ifdef __GNUC__
+#define CHECK_TYPE(var, type) { \
+ typeof(var) *__tmp; \
+ __tmp = (type *)NULL; \
+ (void)__tmp; \
+} (void)0
+
+#define CHECK_TYPE_PAIR(var_a, var_b) { \
+ typeof(var_a) *__tmp; \
+ __tmp = (typeof(var_b) *)NULL; \
+ (void)__tmp; \
+} (void)0
+
+#define CHECK_TYPE_PAIR_INLINE(var_a, var_b) ((void)({ \
+ typeof(var_a) *__tmp; \
+ __tmp = (typeof(var_b) *)NULL; \
+ (void)__tmp; \
+}))
+
+#else
+# define CHECK_TYPE(var, type)
+# define CHECK_TYPE_PAIR(var_a, var_b)
+# define CHECK_TYPE_PAIR_INLINE(var_a, var_b) (void)0
+#endif
+
+/* can be used in simple macros */
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+# define CHECK_TYPE_INLINE(val, type) \
+ (void)((void)(((type)0) != (0 ? (val) : ((type)0))), \
+ _Generic((val), type: 0, const type: 0))
+#else
+# define CHECK_TYPE_INLINE(val, type) \
+ ((void)(((type)0) != (0 ? (val) : ((type)0))))
+#endif
+
+#define CHECK_TYPE_NONCONST(var) { \
+ void *non_const = 0 ? (var) : NULL; \
+ (void)non_const; \
+} (void)0
+
+#endif /* __BLI_COMPILER_TYPECHECK_H__ */