1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00
LibrePilot/flight/pios/inc/pios_struct_helper.h
Alessio Morale e91bc28667 OP-1058 Get rid of Unions.
They caused stack usage increase with -fstrict-aliasing as stack slots are not reused when dealing with unions.
It has now been added the cast_struct_to_array macro in pios_struct_helper.h to handle such case where it is useful to access those homogeneous structs as arrays

+review OPReview-552
2013-09-01 12:10:55 +02:00

30 lines
1001 B
C

/* Taken from include/linux/kernel.h from the Linux kernel tree */
/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#ifndef PIOS_STRUCT_HELPER_H
#define PIOS_STRUCT_HELPER_H
#define container_of(ptr, type, member) \
({ \
const typeof(((type *)0)->member) * __mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type, member)); } \
)
/**
* cast_struct_to_array casts an homogeneous structure instance to an array
* of typeof(struct_field). struct_field need to be any of the fields
* containing inside the struct
* @instance: homogeneous structure to cast
* @struct_field: a field contained inside the structure
*/
#define cast_struct_to_array(instance, struct_field) \
((typeof(struct_field) *) & (instance))
#endif /* PIOS_STRUCT_HELPER_H */