Array and member size helpers.
More...
|
| #define | PBL_IS_ARRAY(array) |
| | Fail the build if the argument is not an array.
|
| |
| #define | PBL_ARRAY_SIZE(array) ((size_t)(PBL_IS_ARRAY(array) + sizeof(array) / sizeof((array)[0]))) |
| | Get the number of elements of an array.
|
| |
| #define | PBL_STATIC_ARRAY_SIZE(type, array) (sizeof((type[])array) / sizeof(type)) |
| | Get the number of elements of an array literal, as a compile-time constant.
|
| |
| #define | PBL_SIZEOF_FIELD(type, member) sizeof(((type *)0)->member) |
| | Get the size of a structure member without an instance.
|
| |
Array and member size helpers.
◆ PBL_ARRAY_SIZE
| #define PBL_ARRAY_SIZE |
( |
|
array | ) |
((size_t)(PBL_IS_ARRAY(array) + sizeof(array) / sizeof((array)[0]))) |
Get the number of elements of an array.
Fails the build if array is a pointer.
- Parameters
-
- Returns
- Number of elements, as a constant expression.
◆ PBL_IS_ARRAY
| #define PBL_IS_ARRAY |
( |
|
array | ) |
|
Value: ((int)sizeof(struct { \
"argument must be an array"); \
}))
#define PBL_TYPES_COMPATIBLE(a, b)
Constant expression: 1 if the two types are compatible, else 0.
Definition compiler.h:156
Fail the build if the argument is not an array.
A pointer, such as an array parameter, has the type of its first element's address; an array does not.
- Parameters
-
| array | Expression to check. |
- Returns
- 0, as a constant expression.
◆ PBL_SIZEOF_FIELD
| #define PBL_SIZEOF_FIELD |
( |
|
type, |
|
|
|
member |
|
) |
| sizeof(((type *)0)->member) |
Get the size of a structure member without an instance.
- Parameters
-
| type | Structure type. |
| member | Member name. |
- Returns
- Size of the member in bytes.
◆ PBL_STATIC_ARRAY_SIZE
| #define PBL_STATIC_ARRAY_SIZE |
( |
|
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;
#define PBL_STATIC_ARRAY_SIZE(type, array)
Get the number of elements of an array literal, as a compile-time constant.
Definition size.h:55
- Parameters
-
| type | Type of the elements. |
| array | Brace-enclosed array literal. |
- Returns
- Number of elements.