• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Are functions called within inline functions forced inline as well?

clickynext

Platinum Member
//FILE1.cpp:
extern"C" void foo()
{
//some code
}

//FILE2:
__forceinline void bar()
{
foo();
}

Does foo exist in only one memory location, or is there a copy of it wherever there is bar?

Thanks!
 
Originally posted by: nickbits
foo() will not be made inline in bar()

Rather, it won't be forced to be inlined with bar. If foo is simple enough many compilers will automatically inline simple functions as an optimization.
 
Originally posted by: Cogman
Originally posted by: nickbits
foo() will not be made inline in bar()

Rather, it won't be forced to be inlined with bar. If foo is simple enough many compilers will automatically inline simple functions as an optimization.

Not if the functions are in different files, as suggested by the comments.
 
Originally posted by: degibson
Originally posted by: Cogman
Originally posted by: nickbits
foo() will not be made inline in bar()

Rather, it won't be forced to be inlined with bar. If foo is simple enough many compilers will automatically inline simple functions as an optimization.

Not if the functions are in different files, as suggested by the comments.

Visual C++ can. Visual Studio 2005 and later have "Whole Program Optimization," which can inline functions that are defined in different compilation units.
 
Re: Inlining functions across files
Originally posted by: Venix
Visual C++ can. Visual Studio 2005 and later have "Whole Program Optimization," which can inline functions that are defined in different compilation units.

Neat.

One last note: In the example, extern "C" forces foo() to have external C-language visibility. Even if you do something exotic with your compiler to force inlining within bar(), foo() still needs to exist as a symbol in the output text. It would be interesting to see how various compilers would react under a constraint of extern "C" inline.
 
In general,m these days you should not inline. Modern compilers should inline things for you. And if you were t oinline to much and it did get inlined, it can actually slow down your code in some cases. Even more reason to let the compiler handle it.

Not to mention that depending on how you are compiling, a modification to something that is inline might not replace it's usage everywhere which can cause bugs. This is more of an argument to never put actually source code in headers though.

Bottom line. Code your code to work and optimize later if it doesn't run on the target hardware fast enough.
 
Back
Top