如何控制手動inline

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"

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章