Inline questions(Not the norm)

Started by
7 comments, last by Void 23 years, 6 months ago
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 }
Advertisement
There''s probably a #pragma which will do it. I don''t know which one though.

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


sharewaregames.20m.com

You can apply the __forceinline (or similar, I don''t remeber right) when you use VC++
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
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|-| ~
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
quote:Original post by MadKeithV

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..

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|-| ~
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
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
quote:Original post by MadKeithV

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
quote:Original post by MadKeithV
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..

This topic is closed to new replies.

Advertisement