Archived

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

Void

Inline questions(Not the norm)

Recommended Posts

Void    126
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 this post


Link to post
Share on other sites
MadKeithV    992
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 this post


Link to post
Share on other sites
Void    126
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..

Share this post


Link to post
Share on other sites
MadKeithV    992
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 this post


Link to post
Share on other sites
milo    122
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 this post


Link to post
Share on other sites
msn12b    390
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

Share this post


Link to post
Share on other sites
Void    126
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..

Share this post


Link to post
Share on other sites