inc/ecu/utils.h File Reference

ECU: inc/ecu/utils.h File Reference
ECU
utils.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ECU_CONTAINER_OF(ptr_, type_, member_)    ((type_ *)(void *)((uint8_t *)(ptr_) - offsetof(type_, member_)))
 Converts an intrusive member back into the data type that stores it. See ECU_DNODE_GET_ENTRY() for example usage. More...
 
#define ECU_CONST_CONTAINER_OF(ptr_, type_, member_)    ((const type_ *)(const void *)((const uint8_t *)(ptr_) - offsetof(type_, member_)))
 Const-qualified version of ECU_CONTAINER_OF(). Converts an intrusive member back into the data type that stores it. See ECU_DNODE_GET_CONST_ENTRY() for example usage. More...
 
#define ECU_FIELD_SIZEOF(type_, member_)    (sizeof(((type_ *)0)->member_))
 Returns the size of a member within a struct or union declaration at compile-time. More...
 
#define ECU_IS_BASE_OF(base_, derived_)    ((bool)(offsetof(derived_, base_) == (size_t)0))
 Verifies, at compile-time, that derived class correctly inherits base class via C-style inheritance. Returns true if this condition is satisfied. False otherwise. More...
 
#define ECU_IS_SIGNED(type_)    ((bool)((type_)-1 < (type_)0))
 Verifies, at compile-time, that supplied type is signed. Returns true if this condition is satisfied. False otherwise. More...
 
#define ECU_IS_UNSIGNED(type_)    ((bool)((type_)-1 > (type_)0))
 Verifies, at compile-time, that supplied type is unsigned. Returns true if this condition is satisfied. False otherwise. More...
 

Detailed Description

See utils.h section in Sphinx documentation.

Author
Ian Ress
Version
0.1
Date
2025-04-13

Macro Definition Documentation

◆ ECU_CONST_CONTAINER_OF

#define ECU_CONST_CONTAINER_OF (   ptr_,
  type_,
  member_ 
)     ((const type_ *)(const void *)((const uint8_t *)(ptr_) - offsetof(type_, member_)))

Const-qualified version of ECU_CONTAINER_OF(). Converts an intrusive member back into the data type that stores it. See ECU_DNODE_GET_CONST_ENTRY() for example usage.

Parameters
ptr_Pointer to intrusive member. This can be pointer to non-const or const.
type_Data type containing the intrusive member that parameter ptr_ points to. Do not use const specifier. I.e. struct my_type, never const struct my_type.
member_Name of intrusive member within type_.

◆ ECU_CONTAINER_OF

#define ECU_CONTAINER_OF (   ptr_,
  type_,
  member_ 
)     ((type_ *)(void *)((uint8_t *)(ptr_) - offsetof(type_, member_)))

Converts an intrusive member back into the data type that stores it. See ECU_DNODE_GET_ENTRY() for example usage.

Parameters
ptr_Pointer to intrusive member. This must be pointer to non-const.
type_Data type containing the intrusive member that parameter ptr_ points to. Do not use const specifier. I.e. struct my_type, never const struct my_type.
member_Name of intrusive member within type_.

◆ ECU_FIELD_SIZEOF

#define ECU_FIELD_SIZEOF (   type_,
  member_ 
)     (sizeof(((type_ *)0)->member_))

Returns the size of a member within a struct or union declaration at compile-time.

Parameters
type_Struct or union type containing member_.
member_Name of member within type_ to get size of.

◆ ECU_IS_BASE_OF

#define ECU_IS_BASE_OF (   base_,
  derived_ 
)     ((bool)(offsetof(derived_, base_) == (size_t)0))

Verifies, at compile-time, that derived class correctly inherits base class via C-style inheritance. Returns true if this condition is satisfied. False otherwise.

Parameters
base_Name of base class member within user's derived_ type.
derived_Derived type to check.

◆ ECU_IS_SIGNED

#define ECU_IS_SIGNED (   type_)     ((bool)((type_)-1 < (type_)0))

Verifies, at compile-time, that supplied type is signed. Returns true if this condition is satisfied. False otherwise.

Parameters
type_Type to check. I.e. int8_t, uint8_t, etc.

◆ ECU_IS_UNSIGNED

#define ECU_IS_UNSIGNED (   type_)     ((bool)((type_)-1 > (type_)0))

Verifies, at compile-time, that supplied type is unsigned. Returns true if this condition is satisfied. False otherwise.

Parameters
type_Type to check. I.e. int8_t, uint8_t, etc.