inc/ecu/utils.h Source File

ECU: inc/ecu/utils.h Source File
ECU
utils.h
Go to the documentation of this file.
1 
14 #ifndef ECU_UTILS_H_
15 #define ECU_UTILS_H_
16 
17 /*------------------------------------------------------------*/
18 /*------------------------- INCLUDES -------------------------*/
19 /*------------------------------------------------------------*/
20 
21 /* STDLib. */
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <stdint.h>
25 
26 /*------------------------------------------------------------*/
27 /*---------------------------- MACROS ------------------------*/
28 /*------------------------------------------------------------*/
29 
42 #define ECU_CONTAINER_OF(ptr_, type_, member_) \
43  ((type_ *)(void *)((uint8_t *)(ptr_) - offsetof(type_, member_)))
44 
58 #define ECU_CONST_CONTAINER_OF(ptr_, type_, member_) \
59  ((const type_ *)(const void *)((const uint8_t *)(ptr_) - offsetof(type_, member_)))
60 
68 #define ECU_FIELD_SIZEOF(type_, member_) \
69  (sizeof(((type_ *)0)->member_))
70 
80 #define ECU_IS_BASE_OF(base_, derived_) \
81  ((bool)(offsetof(derived_, base_) == (size_t)0))
82 
83 /* clang-format off */
91 #define ECU_IS_SIGNED(type_) \
92  ((bool)((type_)-1 < (type_)0))
93 
101 #define ECU_IS_UNSIGNED(type_) \
102  ((bool)((type_)-1 > (type_)0))
103 /* clang-format on */
104 
105 #endif /* ECU_UTILS_H_ */