comparison m_struct.h @ 36768:fd1feb8ae5fd

m_struct: use offsetof instead of a custom hack.
author reimar
date Sun, 16 Feb 2014 16:30:02 +0000
parents 08a90b0e44e1
children eaa58d991a06
comparison
equal deleted inserted replaced
36767:18428293fb7f 36768:fd1feb8ae5fd
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */ 17 */
18 18
19 #ifndef MPLAYER_M_STRUCT_H 19 #ifndef MPLAYER_M_STRUCT_H
20 #define MPLAYER_M_STRUCT_H 20 #define MPLAYER_M_STRUCT_H
21
22 #include <stddef.h>
21 23
22 /// \defgroup OptionsStruct Options struct 24 /// \defgroup OptionsStruct Options struct
23 /// \ingroup Options 25 /// \ingroup Options
24 /// An API to manipulate structs using m_option. 26 /// An API to manipulate structs using m_option.
25 ///@{ 27 ///@{
50 /** \param struct_type Struct type. 52 /** \param struct_type Struct type.
51 * \param member Name of the field. 53 * \param member Name of the field.
52 * \return The offset of the field in bytes. 54 * \return The offset of the field in bytes.
53 */ 55 */
54 #define M_ST_OFF(struct_type, member) \ 56 #define M_ST_OFF(struct_type, member) \
55 ((void*) &((struct_type*) 0)->member) 57 ((void*)offsetof(struct_type, member))
56 58
57 /// Get a pointer to a struct field. 59 /// Get a pointer to a struct field.
58 /** \param struct_p Pointer to the struct. 60 /** \param struct_p Pointer to the struct.
59 * \param struct_offset Offset of the field in the struct. 61 * \param struct_offset Offset of the field in the struct.
60 * \return Pointer to the struct field. 62 * \return Pointer to the struct field.