From: arighi Date: Fri, 24 Sep 2010 13:00:47 +0000 (+0000) Subject: countof(): use STATIC_ASSERT_EXPR() to perform compile-time type checking X-Git-Tag: 2.6.0~105 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=47d46418dff91a1465e95517022abc84607a4da7;p=bertos.git countof(): use STATIC_ASSERT_EXPR() to perform compile-time type checking git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4296 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/compiler.h b/bertos/cfg/compiler.h index 8c217c00..843af838 100644 --- a/bertos/cfg/compiler.h +++ b/bertos/cfg/compiler.h @@ -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