countof(): use STATIC_ASSERT_EXPR() to perform compile-time type checking
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 24 Sep 2010 13:00:47 +0000 (13:00 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 24 Sep 2010 13:00:47 +0000 (13:00 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4296 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/cfg/compiler.h

index 8c217c009641115685977aac40ab046aacaaf19c..843af838c502621f473713c8dff6a945357b28e6 100644 (file)
@@ -540,10 +540,10 @@ typedef unsigned char sigmask_t; /**< Type for signal masks. */
                 * NOTE: the construct __builtin_types_compatible_p() is only
                 * available for C.
                 */
-               #define countof(a) (sizeof(a) / sizeof(*(a)) + \
-                       sizeof(typeof(int[1 - 2 * \
-                               !!__builtin_types_compatible_p(typeof(a), \
-                                               typeof(&a[0]))])) * 0)
+               #define countof(a) (sizeof(a) / sizeof(*(a)) +          \
+                               STATIC_ASSERT_EXPR(                     \
+                                       !__builtin_types_compatible_p(  \
+                                               typeof(a), typeof(&a[0]))))
        #else
                #define countof(a)  (sizeof(a) / sizeof(*(a)))
        #endif