Locally disable the attachment function

I need to make the compiler not inline the inline function. eg:

I have a built-in A .

I have a function Bed and , which is A .
In B , A is built in and it is perfect.

Now I have a C function that calls A many times .
In C , A is built in, and that's not good.

Is it possible to tell the compiler not to embed A when it is called from C ?

- edit -

The first idea is to create a function __ declspec (noinline) A1 (which simply calls A ) and causes the A1 instead of A in the C .
But I wonder if there is a more elegant solution?

note
I know that inline is just a suggestion, but in my program I have some unlikely or erroneous cases when the inline functions of the compiler, but should not, because in these cases I prefer function calls to reduce the size of the code. I also noticed that the compiler can not always make the best choice (from the point of view of the developer)

+3
source share
4 answers

:

template <class F> ALWAYS_INLINE F NOINLINE( F f ) {

  return f;
}

, ( , MSVC) , :

NOINLINE(my_inline_function)();

, " -" Nick D

+1

, . , inline, .

. , GCC noinline, .

- :

inline void a() { ... }

void __attribute__((noinline)) wrap_a()
{ a(); }

void b() {  a(); }

void c() { wrap_a(); }
+7

- - , ​​ . .

+4

The most direct solution is to put the function code in a separate file.

0
source

Source: https://habr.com/ru/post/1789213/


All Articles