#### Archived

This topic is now archived and is closed to further replies.

# Inline questions(Not the norm)

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

## Recommended Posts

I understand that if a function is inline, the whole code is inserted into each place the function is called.. so if two cpp files calls the function, the two .obj files will contain copies of the inlined function. What happens if the compiler decides not to inline it? Will the function code only be pasted in one .obj file and all other .obj have external linkage to it? Is there a way to explicitly specify to the compiler that I don''t want the function to be inlined, while placing the member function inside a header only (because the function code is quite large and called often.) I want to avoid placing the definition in another cpp file as it is a small class. Something like  class C { public: void NoInline() {}; // don''t want this to be inline because it''s large } 

##### Share on other sites
There''s probably a #pragma which will do it. I don''t know which one though.

------------------------------
#pragma twice

##### Share on other sites
You can apply the __forceinline (or similar, I don''t remeber right) when you use VC++

##### Share on other sites
If you don''t specify anything specifically, and you do have a large function, the compiler will probably decide itself not to inline it. Even the "inline" keyword is only a compiler hint, it is not required to inline the function at all.

So, I don''t think you need to do anything special, just type out the function in the header, and you''ll have what you need.

People might not remember what you said, or what you did, but they will always remember how you made them feel.
~ (V)^|) |<é!t|-| ~

##### Share on other sites
quote:

If you don''t specify anything specifically, and you do have a large function, the compiler will probably decide itself not to inline it. Even the "inline" keyword is only a compiler hint, it is not required to inline the function at all.

Is there some sort of way to guarantee that the compiler will not inline it.. something like __forceNoInline..

a pragma might work.. I will look into it..

##### Share on other sites
Why would you want to force it to NOT inline? The compiler is smart enough to know when a function is too big to inline....

People might not remember what you said, or what you did, but they will always remember how you made them feel.
~ (V)^|) |<é!t|-| ~

##### Share on other sites
quote:
Original post by tcs
You can apply the __forceinline (or similar, I don''t remeber right) when you use VC++

__forceinline means the compiler does not perform the cost benefit analysis to decide if the function gets inlined. There are still several reasons why the compiler will not inline the function. Go look up __forceinline in MSDN index for more info.

Mike Roberts
aka milo
mlbobs@telocity.com

##### Share on other sites
quote:

Why would you want to force it to NOT inline? The compiler is smart enough to know when a function is too big to inline....

People might not remember what you said, or what you did, but they will always remember how you made them feel.
~ (V)^|) |<é!t|-| ~

For the truly psychotic, making sure a templatized operator overloaded scheme is done completely inline, w/o function calls.

MSN

##### Share on other sites
quote:
Why would you want to force it to NOT inline? The compiler is smart enough to know when a function is too big to inline....

Ah..it''s an error translation function (error code to string) in an exception class that is called by the constructor of the class..

Ideally, the translation function should be static..but then it wouldn''t be able to access the class members..

It would just cause the exe to bloat if the compiler tries to inline it.. though I don''t think it would, but I would just like to see if there is such an option of making sure it doesn''t..

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

• 11
• 34
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631412
• Total Posts
2999939
×