Utility macros and functions to improve quality of life.
|
| #define | MM_MIN(_x, _y) (((_x) < (_y)) ? (_x) : (_y)) |
| | Get the minimum of 2 values. More...
|
| |
| #define | MM_MAX(_x, _y) (((_x) > (_y)) ? (_x) : (_y)) |
| | Get the maximum of 2 values. More...
|
| |
| #define | MM_FAST_ROUND_UP(x, m) ((((x) - 1) | ((m) - 1)) + 1) |
| | Round x up to the next multiple of m (where m is a power of 2). More...
|
| |
| #define | MM_UNUSED(_x) (void)(_x) |
| | Casts the given expression to void to avoid "unused" warnings from the compiler. More...
|
| |
| #define | MM_PACKED __attribute__((packed)) |
| | Tells the compiler to pack the structure. More...
|
| |
| #define | MM_WEAK __attribute__((weak)) |
| | Used to declare a weak symbol. More...
|
| |
| #define | MM_FALLTHROUGH __attribute__((fallthrough)) |
| | Allows a case to fallthrough to the next case in a switch case. More...
|
| |
| #define | MM_STATIC_ASSERT(_expression, _message) _Static_assert((_expression), _message) |
| | Assertion check that is evaluated at compile time. More...
|
| |
| #define | MM_ARRAY_COUNT(_a) (sizeof(_a) / sizeof((_a)[0])) |
| | Return the number of elements in the given array. More...
|
| |
| #define | MM_MEMBER_SIZE(_type, _member) (sizeof(((_type *)0)->_member)) |
| | Return the size of a structs member. More...
|
| |
|
| static char | mm_nibble_to_hex_char (uint8_t nibble) |
| | Convert the least significant 4 bits of the given argument to a character representing their hexadecimal value. More...
|
| |
◆ MM_ARRAY_COUNT
| #define MM_ARRAY_COUNT |
( |
|
_a | ) |
(sizeof(_a) / sizeof((_a)[0])) |
Return the number of elements in the given array.
- Parameters
-
| _a | The array to get the element count for. Note that this must be an array and not a pointer. Beware that array-type function arguments are actually treated as pointers by the compiler. Must not be NULL. |
- Returns
- the count of elements in the given array.
Definition at line 110 of file mmutils.h.
◆ MM_FALLTHROUGH
| #define MM_FALLTHROUGH __attribute__((fallthrough)) |
Allows a case to fallthrough to the next case in a switch case.
Definition at line 83 of file mmutils.h.
◆ MM_FAST_ROUND_UP
| #define MM_FAST_ROUND_UP |
( |
|
x, |
|
|
|
m |
|
) |
| ((((x) - 1) | ((m) - 1)) + 1) |
Round x up to the next multiple of m (where m is a power of 2).
- Warning
m must be a power of 2.
Definition at line 65 of file mmutils.h.
◆ MM_MAX
| #define MM_MAX |
( |
|
_x, |
|
|
|
_y |
|
) |
| (((_x) > (_y)) ? (_x) : (_y)) |
Get the maximum of 2 values.
Note that this macro is not ideal and should be used with caution. Caveats include:
- The two parameters may be evaluated more than once, so should be constant values that do not have side effects. For example, do NOT do
MM_MAX(a++, b).
- There are no explicit constraints on types, so be careful of comparing different integer types, etc.
- Parameters
-
| _x | The first value to compare. |
| _y | The second value to compare. |
- Returns
- the maximum of
_x and _y.
Definition at line 57 of file mmutils.h.
◆ MM_MEMBER_SIZE
| #define MM_MEMBER_SIZE |
( |
|
_type, |
|
|
|
_member |
|
) |
| (sizeof(((_type *)0)->_member)) |
Return the size of a structs member.
- Parameters
-
| _type | The struct type |
| _member | The name of the member to get the size of. |
- Returns
- the size of the struct member.
Definition at line 120 of file mmutils.h.
◆ MM_MIN
| #define MM_MIN |
( |
|
_x, |
|
|
|
_y |
|
) |
| (((_x) < (_y)) ? (_x) : (_y)) |
Get the minimum of 2 values.
Note that this macro is not ideal and should be used with caution. Caveats include:
- The two parameters may be evaluated more than once, so should be constant values that do not have side effects. For example, do NOT do
MM_MIN(a++, b).
- There are no explicit constraints on types, so be careful of comparing different integer types, etc.
- Parameters
-
| _x | The first value to compare. |
| _y | The second value to compare. |
- Returns
- the minimum of
_x and _y.
Definition at line 41 of file mmutils.h.
◆ MM_PACKED
| #define MM_PACKED __attribute__((packed)) |
Tells the compiler to pack the structure.
Definition at line 73 of file mmutils.h.
◆ MM_STATIC_ASSERT
| #define MM_STATIC_ASSERT |
( |
|
_expression, |
|
|
|
_message |
|
) |
| _Static_assert((_expression), _message) |
Assertion check that is evaluated at compile time.
The constant expression, _expression, is evaluted at compile time. If zero then it triggers a compilation error and _message is displayed. If non-zero, no code is emitted.
- Parameters
-
| _expression | Constant expression to evaluate. If zero then a compilation error is triggered. |
| _message | Message to display on error. |
Definition at line 98 of file mmutils.h.
◆ MM_UNUSED
| #define MM_UNUSED |
( |
|
_x | ) |
(void)(_x) |
Casts the given expression to void to avoid "unused" warnings from the compiler.
Definition at line 69 of file mmutils.h.
◆ MM_WEAK
| #define MM_WEAK __attribute__((weak)) |
Used to declare a weak symbol.
Definition at line 78 of file mmutils.h.
◆ mm_nibble_to_hex_char()
| static char mm_nibble_to_hex_char |
( |
uint8_t |
nibble | ) |
|
|
inlinestatic |
Convert the least significant 4 bits of the given argument to a character representing their hexadecimal value.
For example, for input 0xde this will return 'E', for 0x01 it will return '1'.
- Parameters
-
| nibble | The input nibble (upper 4 bits will be discarded). |
- Returns
- The character that represents the hexadecimal value of the lower 4 bits of
nibble. Values greater than 0x09 will be represented with upper case characters.
Definition at line 134 of file mmutils.h.