Defining a Macro to Return the Number of Elements in an Array Posted by jimfred on 2015-12-16 01:11 I use this in OpenStm32 and with other toolsets: #define COUNT_OF(x) ((sizeof(x)/sizeof(0x)) / ((size_t)(!(sizeof(x) % sizeof(0x))))) See this for more info.