remove \r
[extl.git] / extl / utility / offset_of.h
blob4936416535229b4aefdc99b9bd5d84b590449ebf
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: offsetof.h
4 * Created: 08.02.22
5 * Updated: 08.05.05
7 * Brief: The offset of a given member within a class, struct or union type
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_UTILITY_OFFSET_OF_H
14 #define EXTL_UTILITY_OFFSET_OF_H
16 /*!\file offsetof.h
17 * \brief The offset of a given member within a class, struct or union type
20 /* ///////////////////////////////////////////////////////////////////////
21 * Includes
23 #include "../config/config.h"
25 /* ///////////////////////////////////////////////////////////////////////
26 * Macros
28 #ifdef EXTL_OFFSET_OF
29 # undef EXTL_OFFSET_OF
30 #endif
32 #ifdef __cplusplus
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)
37 # else
38 # define EXTL_OFFSET_OF(S, M) \
39 (reinterpret_cast< EXTL_NS(e_size_t) >(&reinterpret_cast<S*>(0)->M))
40 # endif
41 #else
42 # define EXTL_OFFSET_OF(S, M) ((e_size_t)&((S*)(0))->M)
43 #endif
45 /* ///////////////////////////////////////////////////////////////////////
46 * Unit-testing
48 #ifdef EXTL_UTILITY_OFFSET_OF_TEST_ENABLE
49 # include "unit_test/offset_of_test.h"
50 #endif
52 /* //////////////////////////////////////////////////////////////////// */
53 #endif /* EXTL_UTILITY_OFFSET_OF_H */
54 /* //////////////////////////////////////////////////////////////////// */