PER Firmware
Loading...
Searching...
No Matches
countof.h File Reference

macro-based countof implementation More...

Go to the source code of this file.

Macros

#define _COUNTOF_IS_ARRAY(x)
 
#define countof(array)
 

Detailed Description

macro-based countof implementation

Helper macro to count the number of elements in an array. Passing a pointer is rejected at compile time.

Author
Irving Wang (irvin.nosp@m.gw@p.nosp@m.urdue.nosp@m..edu)

Macro Definition Documentation

◆ _COUNTOF_IS_ARRAY

#define _COUNTOF_IS_ARRAY ( x)
Value:
(!__builtin_types_compatible_p(typeof(x), typeof(&(x)[0])))

◆ countof

#define countof ( array)
Value:
({ \
static_assert(_COUNTOF_IS_ARRAY(array), \
"countof() argument must be an array"); \
(sizeof(array) / sizeof((array)[0])); \
}) \