CMagic  0.5.0
Portable C library of utilities and data structures
utils.h
Go to the documentation of this file.
1 
6 #ifndef CMAGIC_UTILS_H
7 #define CMAGIC_UTILS_H
8 
9 #include <stddef.h>
10 #include <stdint.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
19 #define CMAGIC_UTILS_DIV_CEIL(dividend, divisor) (((dividend) + (divisor) - 1) / (divisor))
20 
26 #define CMAGIC_UTILS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
27 
33 #define CMAGIC_UTILS_ASSERT_SAME_TYPE(expr1, expr2) ((void)sizeof(&(expr1)-&(expr2)))
34 
38 #define CMAGIC_UTILS_MIN(val1, val2) ((val1) < (val2) ? (val1) : (val2))
39 
43 #define CMAGIC_UTILS_MAX(val1, val2) ((val1) > (val2) ? (val1) : (val2))
44 
51 uintptr_t
52 cmagic_utils_align_address_up(uintptr_t unaligned_addr,
53  size_t required_alignment);
54 
61 uintptr_t
62 cmagic_utils_align_address_down(uintptr_t unaligned_addr,
63  size_t required_alignment);
64 
65 #ifdef __cplusplus
66 } // extern "C"
67 #endif
68 
69 #endif /* CMAGIC_UTILS_H */
uintptr_t cmagic_utils_align_address_down(uintptr_t unaligned_addr, size_t required_alignment)
Decreases the address if it&#39;s not aligned.
uintptr_t cmagic_utils_align_address_up(uintptr_t unaligned_addr, size_t required_alignment)
Increases the address if it&#39;s not aligned.