PebbleOS
Loading...
Searching...
No Matches
Macros

Array and member size helpers. More...

Macros

#define ARRAY_LENGTH(array)   (sizeof((array)) / sizeof((array)[0]))
 Calculate the length of an array, based on the size of the element type.
 
#define STATIC_ARRAY_LENGTH(type, array)   (sizeof((type[])array) / sizeof(type))
 Get the number of elements of an array literal, as a compile-time constant.
 
#define MEMBER_SIZE(type, member)   sizeof(((type *)0)->member)
 Get the size of a structure member without an instance.
 

Detailed Description

Array and member size helpers.

Macro Definition Documentation

◆ ARRAY_LENGTH

#define ARRAY_LENGTH (   array)    (sizeof((array)) / sizeof((array)[0]))

Calculate the length of an array, based on the size of the element type.

Parameters
arrayThe array to be evaluated.
Returns
The length of the array.

◆ MEMBER_SIZE

#define MEMBER_SIZE (   type,
  member 
)    sizeof(((type *)0)->member)

Get the size of a structure member without an instance.

Parameters
typeStructure type.
memberMember name.
Returns
Size of the member in bytes.

◆ STATIC_ARRAY_LENGTH

#define STATIC_ARRAY_LENGTH (   type,
  array 
)    (sizeof((type[])array) / sizeof(type))

Get the number of elements of an array literal, as a compile-time constant.

#define RATES {10, 25, 50}
static const uint16_t s_rates[] = RATES;
_Static_assert(STATIC_ARRAY_LENGTH(uint16_t, RATES) == 3, "");
#define STATIC_ARRAY_LENGTH(type, array)
Get the number of elements of an array literal, as a compile-time constant.
Definition size.h:33
Parameters
typeType of the elements.
arrayBrace-enclosed array literal.
Returns
Number of elements.