purpose:
通過宏_INLINE_ON來控制函數是否inline, 非inline函數有利於在vtune等profiling工具中分析。
1. macros.h
#ifdef _WIN32
#define _INLINE_ON
#endif
#ifdef _INLINE_ON
#define _INLINE inline
#else // _INLINE_ON
#define _INLINE __attribute__((noinline)) // gcc 's attribute.
#endif
2. test.h
#include "macros.h"
#if defined(_INLINE_ON) || defined(_TEST_CPP) // _defined(_TEST_CPP) 保證只會有一份definition
_INLINE func() {
...
}
_INLINE func2() {
...
}
#endif //if defined(_INLINE_ON) || defined(_TEST_CPP)
3. test.cpp
#define _TEST_CPP
#include "test.h"