|
CMagic
0.5.0
Portable C library of utilities and data structures
|
General purpose utilities. More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Macros | |
| #define | CMAGIC_UTILS_DIV_CEIL(dividend, divisor) (((dividend) + (divisor) - 1) / (divisor)) |
| Performs division of two integers and returns ceiling of the result. More... | |
| #define | CMAGIC_UTILS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) |
| Returns the capacity of the array. More... | |
| #define | CMAGIC_UTILS_ASSERT_SAME_TYPE(expr1, expr2) ((void)sizeof(&(expr1)-&(expr2))) |
| Checks if two L-value expressions have the same type. More... | |
| #define | CMAGIC_UTILS_MIN(val1, val2) ((val1) < (val2) ? (val1) : (val2)) |
| Returns smaller of two values. More... | |
| #define | CMAGIC_UTILS_MAX(val1, val2) ((val1) > (val2) ? (val1) : (val2)) |
| Returns greater of two values. More... | |
Functions | |
| uintptr_t | cmagic_utils_align_address_up (uintptr_t unaligned_addr, size_t required_alignment) |
| Increases the address if it's not aligned. More... | |
| uintptr_t | cmagic_utils_align_address_down (uintptr_t unaligned_addr, size_t required_alignment) |
| Decreases the address if it's not aligned. More... | |
General purpose utilities.
| #define CMAGIC_UTILS_ARRAY_SIZE | ( | array | ) | (sizeof(array) / sizeof((array)[0])) |
Returns the capacity of the array.
| #define CMAGIC_UTILS_ASSERT_SAME_TYPE | ( | expr1, | |
| expr2 | |||
| ) | ((void)sizeof(&(expr1)-&(expr2))) |
Checks if two L-value expressions have the same type.
The expressions must be L-values because this macro needs addresses of them. Subtraction of two pointers without any casting causes compilation error if the types don't match.
| #define CMAGIC_UTILS_DIV_CEIL | ( | dividend, | |
| divisor | |||
| ) | (((dividend) + (divisor) - 1) / (divisor)) |
Performs division of two integers and returns ceiling of the result.
| #define CMAGIC_UTILS_MAX | ( | val1, | |
| val2 | |||
| ) | ((val1) > (val2) ? (val1) : (val2)) |
Returns greater of two values.
| #define CMAGIC_UTILS_MIN | ( | val1, | |
| val2 | |||
| ) | ((val1) < (val2) ? (val1) : (val2)) |
Returns smaller of two values.
| uintptr_t cmagic_utils_align_address_down | ( | uintptr_t | unaligned_addr, |
| size_t | required_alignment | ||
| ) |
Decreases the address if it's not aligned.
| unaligned_addr | original address |
| required_alignment | required alignment of the resulting address |
unaligned_addr rounded DOWN so it's divisible by required_alignment | uintptr_t cmagic_utils_align_address_up | ( | uintptr_t | unaligned_addr, |
| size_t | required_alignment | ||
| ) |
Increases the address if it's not aligned.
| unaligned_addr | original address |
| required_alignment | required alignment of the resulting address |
unaligned_addr rounded UP so it's divisible by required_alignment
1.8.13