So force inlining through compiler extensions. What's the problem? |
Thanks. It seems the most appropriate solution.
One more thing, sharing you trick for the same (Not tried but might work). |
...
Maybe understand some thing not right.
But here is the code on which i've tried to check inlining:
1 2 3 4 5 6 7 8 9 10 11 12
|
// tajendra.h
#include <cstdio>
static inline
void callToInlineFunctionFromFile(const char *filename) /* __attribute__((always_inline)) */;
static inline
void callToInlineFunctionFromFile(const char *filename)
{
static int counter = 0;
printf("Call came from file %s and counter value is now %i\n", filename, ++counter);
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// tajendra.cpp
#include <cstdlib>
#include "tajendra.h"
extern void callToInlineFunctionFromOtherFile(void);
int main(void)
{
callToInlineFunctionFromFile(__FILE__);
callToInlineFunctionFromOtherFile();
callToInlineFunctionFromFile(__FILE__);
callToInlineFunctionFromOtherFile();
return EXIT_SUCCESS;
}
|
1 2 3 4 5 6 7
|
// tajendra2.cpp
#include "tajendra.h"
void callToInlineFunctionFromOtherFile()
{
callToInlineFunctionFromFile(__FILE__);
}
|
When i declared and defined a function as a static inline, i've got th next output:
Call came from file tajendra.cpp and counter value is now 1
Call came from file tajendra2.cpp and counter value is now 1
Call came from file tajendra.cpp and counter value is now 2
Call came from file tajendra2.cpp and counter value is now 2
But when i declared it as extern inline (and without extern) and defined as inline:
Call came from file tajendra.cpp and counter value is now 1
Call came from file tajendra2.cpp and counter value is now 2
Call came from file tajendra.cpp and counter value is now 3
Call came from file tajendra2.cpp and counter value is now 4
In both cases the function was inlined (i've checked the asm code). So maybe i understand something not right, but i don't understand how this can help in figuring out about was the function inlined.