commit f59dee8c863c5cccd4e168906b165f4637c7de9b parent 054a9c41f3bd637b1f182c3fc8b2f4103c36f0e2 Author: Michael Savage <mikejsavage@gmail.com> Date: Sun Nov 20 10:14:23 +0200 Safer ARRAY_COUNT Diffstat:
intrinsics.h | | | 6 | ++++-- |
diff --git a/intrinsics.h b/intrinsics.h @@ -36,8 +36,10 @@ typedef uintptr_t uptr; #define U32_MAX u32( UINT32_MAX ) #define U64_MAX u64( UINT64_MAX ) -#define array_count( x ) ( sizeof( x ) / sizeof( ( x )[ 0 ] ) ) -#define ARRAY_COUNT array_count +template< typename T, size_t N > +char ( &ArrayCountObj( const T ( & )[ N ] ) )[ N ]; +#define ARRAY_COUNT( arr ) ( sizeof( ArrayCountObj( arr ) ) ) +#define array_count ARRAY_COUNT #define is_power_of_2( n ) ( ( ( n ) & ( ( n ) - 1 ) ) == 0 )