shithub: orca

Download patch

ref: 41d8139955e7a62a0ff57093f19451b5d26d3083
parent: cfacf87e6a66325b258ca1f9c0c74cf1cfdec83a
author: cancel <cancel@cancel.fm>
date: Sat Dec 1 09:41:46 EST 2018

Move array count macro to base.h

--- a/base.h
+++ b/base.h
@@ -48,6 +48,19 @@
 #define ORCA_UNLIKELY(_x) (_x)
 #endif
 
+// array count, safer on gcc/clang
+#if defined(__GNUC__) || defined(__clang__)
+#define ORCA_ASSERT_IS_ARRAY(_array)                                           \
+  (sizeof(char[1 - 2 * __builtin_types_compatible_p(                           \
+                           __typeof(_array), __typeof(&(_array)[0]))]) -       \
+   1)
+#define ORCA_ARRAY_COUNTOF(_array)                                             \
+  (sizeof(_array) / sizeof((_array)[0]) + ORCA_ASSERT_IS_ARRAY(_array))
+#else
+// pray
+#define ORCA_ARRAY_COUNTOF(_array) (sizeof(_array) / sizeof(_array[0]))
+#endif
+
 #define ORCA_Y_MAX UINT16_MAX
 #define ORCA_X_MAX UINT16_MAX
 
--- a/sim.c
+++ b/sim.c
@@ -141,18 +141,6 @@
   return val;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#define ORCA_ASSERT_IS_ARRAY(_array)                                           \
-  (sizeof(char[1 - 2 * __builtin_types_compatible_p(                           \
-                           __typeof(_array), __typeof(&(_array)[0]))]) -       \
-   1)
-#define ORCA_ARRAY_COUNTOF(_array)                                             \
-  (sizeof(_array) / sizeof((_array)[0]) + ORCA_ASSERT_IS_ARRAY(_array))
-#else
-// pray
-#define ORCA_ARRAY_COUNTOF(_array) (sizeof(_array) / sizeof(_array[0]))
-#endif
-
 #define ORCA_EXPAND_SOLO_OPER_CHARS(_oper_char, _oper_name)                    \
   Orca_oper_char_##_oper_name = _oper_char,
 #define ORCA_EXPAND_DUAL_OPER_CHARS(_upper_oper_char, _lower_oper_char,        \