m_struct: try to be more standard C

The main problem is that this m_struct stuff uses pointers for offsets
(why...), so we mangle it by intptr_t. This stuff really should use ints
(or in theory ptrdiff_t) for offsets, but changing it would be too much
effort, and hopefully this m_struct stuff will go away and replaced by
the common option parser mechanism instead.

Shuts up warnings on Windows.

Patch suggested by jon_y and rossy on IRC.
This commit is contained in:
wm4 2013-07-12 18:40:08 +02:00
parent aa3b8c8fe7
commit 9dfc7daf79
1 changed files with 5 additions and 5 deletions

View File

@ -19,6 +19,9 @@
#ifndef MPLAYER_M_STRUCT_H
#define MPLAYER_M_STRUCT_H
#include <stddef.h>
#include <inttypes.h>
#include "core/bstr.h"
/// \defgroup OptionsStruct Options struct
@ -46,15 +49,12 @@ typedef struct m_struct_st {
} m_struct_t;
// From glib.h (modified ;-)
/// Get the offset of a struct field.
/** \param struct_type Struct type.
* \param member Name of the field.
* \return The offset of the field in bytes.
*/
#define M_ST_OFF(struct_type, member) \
((void*) &((struct_type*) 0)->member)
#define M_ST_OFF (void *)(uintptr_t)offsetof
/// Get a pointer to a struct field.
/** \param struct_p Pointer to the struct.
@ -62,7 +62,7 @@ typedef struct m_struct_st {
* \return Pointer to the struct field.
*/
#define M_ST_MB_P(struct_p, struct_offset) \
((void *)((char *)(struct_p) + (unsigned long)(struct_offset)))
((void *)((char *)(struct_p) + (uintptr_t)(struct_offset)))
/// Access a struct field at a given offset.
/** \param member_type Type of the field.