|
-
November 26th, 2001, 05:25 AM
#1
How to prevent a small function from being inline?
Hi,
How can I prevent a very small function from being inline?
I have to put that function in the header file because belongs to a template class, and I must ensure that it's not inline because contains a static member variable that must be unique through the program.
-
November 26th, 2001, 01:02 PM
#2
Re: How to prevent a small function from being inline?
First of all, the compile should be able to handle the unique static. If not, the compiler's broken.
Otherwise, there's not Standardized way of saying "don't inline". You either specifically say to inline or you don't. In the latter case, it's pure implementation defined whether or not it's inlined.
In MSVC++, use a pragma:
#pragma auto_inline(off)
void non_inlined_func()
{
}
#pragma auto_inline() // returns to previous state
Truth,
James
http://www.NJTheater.com
http://www.NovelTheory.com
I don't do it for the points (OK, maybe I do), but rating a post is a good way for me to know if I helped.
-
November 26th, 2001, 03:33 PM
#3
Re: How to prevent a small function from being inline?
Change the following compiler setting within the project settings (ATL+F7):
Register C/C++ -> Category Optimizations -> Inline function expansion: Disable
That should do the trick...
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
-
November 27th, 2001, 06:04 AM
#4
Re: How to prevent a small function from being inline?
Applying the following code in release build, I don't think that it works. Any ideas why?
(I use MSVC++ 6.0 + SP5)
template <class T>
class Template_class
{
public:
static int& get();
};
#pragma auto_inline(off)
template <class T>
int& Template_class<T>::get() { static int the_static_variable=0; return the_static_variable; }
#pragma auto_inline()
Thanks for replying.
-
November 27th, 2001, 07:55 AM
#5
Re: How to prevent a small function from being inline?
I think your codes doesn't involve "inline".whether you use #pragma auto_inline() or not, it cannot work. In your case, when a new instantiation of template_class was created, a new "static the_static_variable" then be created.
so ,for example, template_class<int> and template_class<double> will both have a static variable "the_static_variable". They can be accessed by template_class<int>::get() and template_class<double>::get() respectively, and these two variable are independent from each other.
Since going backward is not the answer,how do we move forward?
Kylin Li
-
November 27th, 2001, 08:50 AM
#6
Re: How to prevent a small function from being inline?
Try putting the #pragma around where the class is instaniated:#pragma auto_inline(off)
Template_class<int> int_Temp;
#pragma auto_inline()
Truth,
James
http://www.NJTheater.com
http://www.NovelTheory.com
I don't do it for the points (OK, maybe I do), but rating a post is a good way for me to know if I helped.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|