Force inline functions in C++
-
- Posts: 8
- Joined: Tue Feb 24, 2009 1:51 pm
Force inline functions in C++
Hi, is possible force the inline functions when I compile a source with gcc?
Ps. Sorry for my bad English.... I'm not English
Ps. Sorry for my bad English.... I'm not English
Re: Force inline functions in C++
Maybe -finline-functions ?
Please correct my English. If you'll find mistake please tell me about it so I can improve my English.
Re: Force inline functions in C++
erm sorry for the possible noob question , but can't you just declare them "inline" and that's it?
One Tequila, Two Tequila, Three Tequila, Floor!
-
- Posts: 8
- Joined: Tue Feb 24, 2009 1:51 pm
Re: Force inline functions in C++
So the compiler decides if he want expand them or use them as functions.... I want force the expanding
Re: Force inline functions in C++
You can force it with a gcc attribute:
static void inline __attribute__((always_inline)) yourFunction() ...
static void inline __attribute__((always_inline)) yourFunction() ...
-
- Posts: 8
- Joined: Tue Feb 24, 2009 1:51 pm
Re: Force inline functions in C++
I must declare it as static?
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Force inline functions in C++
Well, no, static just tells the compiler/linker that that function can only be used in the file that it is defined and written in.
-
- Member
- Posts: 524
- Joined: Sun Nov 09, 2008 2:55 am
- Location: Pennsylvania, USA
Re: Force inline functions in C++
Its a good idea to prevent clashes if you're puting the function inside of a header file. Otherwise each object file could export this function, leading to multiple definition errors when you link.
Re: Force inline functions in C++
In some cases, forcing the inlining isn't a good idea, so make sure you are aware of the implications, e.g. when using virtual functions. (Read Scott Meyers' "Effective C++"?)
Every good solution is obvious once you've found it.
-
- Posts: 8
- Joined: Tue Feb 24, 2009 1:51 pm
Re: Force inline functions in C++
Yes but if I had to write a for cycle, I'd prefare write it as inline function that a real function (isn't faster???)In some cases, forcing the inlining isn't a good idea, so make sure you are aware of the implications, e.g. when using virtual functions.
Re: Force inline functions in C++
Simply declare the function 'inline' (and define it in the header file) and let the compiler decide whether to actually inline it or not. That's why 'inline' is merely a suggestion: The compiler knows more about the generated code than you do. (Usually.)
"Forcing" something is almost never a good idea.
"Forcing" something is almost never a good idea.
Every good solution is obvious once you've found it.