1 /* ///////////////////////////////////////////////////////////////////////
7 * Brief: The offset of a given member within a class, struct or union type
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_UTILITY_OFFSET_OF_H
14 #define EXTL_UTILITY_OFFSET_OF_H
17 * \brief The offset of a given member within a class, struct or union type
20 /* ///////////////////////////////////////////////////////////////////////
23 #include "../config/config.h"
25 /* ///////////////////////////////////////////////////////////////////////
29 # undef EXTL_OFFSET_OF
33 /* GCC warning: invalid access to non-static data member of NULL object */
34 # if defined(EXTL_COMPILER_IS_GCC)
35 # define EXTL_OFFSET_OF(S, M) \
36 (reinterpret_cast< EXTL_NS(e_size_t) >(&reinterpret_cast<S*>(1)->M) - 1)
38 # define EXTL_OFFSET_OF(S, M) \
39 (reinterpret_cast< EXTL_NS(e_size_t) >(&reinterpret_cast<S*>(0)->M))
42 # define EXTL_OFFSET_OF(S, M) ((e_size_t)&((S*)(0))->M)
45 /* ///////////////////////////////////////////////////////////////////////
48 #ifdef EXTL_UTILITY_OFFSET_OF_TEST_ENABLE
49 # include "unit_test/offset_of_test.h"
52 /* //////////////////////////////////////////////////////////////////// */
53 #endif /* EXTL_UTILITY_OFFSET_OF_H */
54 /* //////////////////////////////////////////////////////////////////// */