# Unity Inline configuration

This topic is 4906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This is a second part of an old post of mine: http://www.gamedev.net/community/forums/topic.asp?topic_id=284673 in which: - one define USING_INLINE that if it's defined make in compiling all members of the class to be inline, and if not defined, all members are non inline. ( Foo.cpp // include .inl file if is defined USING_INLINE Foo.inl // include .h file and have the code of the class members. Foo.h // class declaration, and include the .inl file and the .inc file Foo.inc // have the "parameters" (defined or not defined USING_INLINE) ) what I want to ask now, although it seems stupid, is to get - other define USING_INLINE_BEST, that if USING_INLINE is defined it do nothing, but if USING_INLINE isn't defined, then it only do some functions inline (functions that you have selected before) using the preprocesor #ifdef/ifndef/endif to englobe what functions you want inline. so much preprocesor is a brainbreaker for me, anyone knows or can think a method to do it? thanks

##### Share on other sites
This should work for VC++, but you also have to set the correct compiler options.

#if defined( USING_INLINE )     #define INLINE __forceinline        // force to be inlined #elif defined( USING_INLINE_BEST )     #define INLINE                      // let the compiler choose #else     #define INLINE __declspec(noinline) // not inlined #endif

Excerpts from Microsoft docs:

/Ob0 Disables inline expansion, which is on by default.
/Ob1 Expands only functions marked as inline or __inline or, in a C++ member function, defined within a class declaration.
/Ob2 Expands functions marked as inline or __inline and any other function that the compiler chooses (expansion occurs at the compiler's discretion, often referred to as auto-inlining).

The __forceinline keyword overrides the cost/benefit analysis and relies on the judgment of the programmer instead.
The inline keyword tells the compiler that inline expansion is preferred.
__declspec(noinline) tells the compiler to never inline a particular member function (function in a class).

Even with __forceinline, the compiler cannot inline code in all circumstances.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
17
5. 5

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631773
• Total Posts
3002265
×