Just today I've found out how to say to both MSVC and GCC, "do not inline this". I have not tried it yet with either compiler. The Microsoft syntax might work for ICC too, I have no idea..wgarvin wrote:By the way, you can force MSVC to inline code with a compiler-specific extension:Here is a similar incantation which should work for GCC:Code: Select all
#define FORCE_INLINE __forceinline FORCE_INLINE void Foo() { }
I usually put these macros in the same header as my base types and other simple platform- or compiler-specific declarations.Code: Select all
#define FORCE_INLINE __inline__ __attribute__((always_inline)) FORCE_INLINE void Foo() { }
...Unfortunately, I don't know of a convenient way to force either compiler NOT to inline code, other than to put the function definition in another .cpp file which the compiler doesn't get to see before it sees the call site. So that's what I do when I need that behaviour, even though its a bit inconvenient.
For Microsoft:
Code: Select all
#define NO_INLINE __declspec(noinline)
Code: Select all
#define NO_INLINE __attribute__((noinline))