The function is defined as
inline void func() { // тело функции }
I noticed that not always the function is really "inline". That is, the compiler somehow decides when to embed, and when not to embed.
The fact is that inline
, in fact, is not intended to embed functions. It is used to declare functions in h-files.
“Making” the compiler inline a function, in fact, there is no universal way, because The standard final solution is left to the compiler. Personally, I do not know a way to force gcc. For mc there is a secret keyword __forceinline
.
I absolutely agree with @kirelagin, "forcing" the compiler to do this is quite difficult. You can help him more with this. And the word inline says nothing. A more accurate way to follow a few rules when creating procedures.
following these simple rules and with the optimization included in the compiler there are good chances for the compiler to "inline" such a procedure
The standard says so:
A function declared in an inline function . The function of the specimen may appear more than once; it appeared only once. It is as fast as possible. This is where you can find out what is effective.
Those. if it is faster not to embed a function, the compiler has the right to do so.
From the gcc documentation:
You can also direct all the “simple enough” functions to their choice of options.
Try to use this key. To check if the inline function has become use the -Winline switch, then the compiler will tell you which functions are converted to built-in
It all depends on the complexity of the function and its size. And it depends on the compiler. In MinGW, it’s not possible to use built-in functions at all, the compiler cursed them.
Source: https://ru.stackoverflow.com/questions/2427/
All Articles