473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Function declarations and inline

MiG
Hello,

I would like to know if including the body of a function in its class
declaration results in the function being inlined.

In other words, is the following code...

template <typename T>
class foo
{
void foobar(T arg)
{
_data = arg;
}

Aug 16 '07 #1
6 1486
MiG wrote:
I would like to know if including the body of a function in its class
declaration results in the function being inlined.
Yes, it does. IOW, it's the same as supplying the function right
after the class definition (outside of it) with 'inline' modifier.
[..]
Now, you probably already know that 'inline' is not a directive to
the compiler, but rather a hint, which the compiler is free to
ignore.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 16 '07 #2
MiG
Victor Bazarov wrote:
MiG wrote:
>I would like to know if including the body of a function in its class
declaration results in the function being inlined.

Yes, it does. IOW, it's the same as supplying the function right
after the class definition (outside of it) with 'inline' modifier.
>[..]

Now, you probably already know that 'inline' is not a directive to
the compiler, but rather a hint, which the compiler is free to
ignore.

V
Thanks for that V, much appreciated!

--
Miguel Guedes
Aug 16 '07 #3
MiG
Victor Bazarov wrote:
MiG wrote:
>I would like to know if including the body of a function in its class
declaration results in the function being inlined.

Yes, it does. IOW, it's the same as supplying the function right
after the class definition (outside of it) with 'inline' modifier.
>[..]

Now, you probably already know that 'inline' is not a directive to
the compiler, but rather a hint, which the compiler is free to
ignore.

V
Victor,

I can't help but ask another question.

Are you against using compiler specific directives such as MsVC's
__forceinline, even when portability across platforms is not an issue?
I'm sure this won't be news for you but in case you don't know (you seem
to be a *nix user :) __forceinline works pretty much in the same way as
the standard inline and only differs in the compiler not performing the
cost/benefit analysis it does for inline functions/methods and a L1
warning being output whenever it can't/won't inline.

--
Miguel Guedes
Aug 16 '07 #4
MiG wrote:
Victor Bazarov wrote:
>MiG wrote:
>>I would like to know if including the body of a function in its
class declaration results in the function being inlined.

Yes, it does. IOW, it's the same as supplying the function right
after the class definition (outside of it) with 'inline' modifier.
>>[..]

Now, you probably already know that 'inline' is not a directive to
the compiler, but rather a hint, which the compiler is free to
ignore.

V

Victor,

I can't help but ask another question.

Are you against using compiler specific directives such as MsVC's
__forceinline, even when portability across platforms is not an issue?
I'm sure this won't be news for you but in case you don't know (you
seem to be a *nix user :)
For the record: I am not really a Unix user, although I can be if
needed. BTW, you could determine that by looking at the headers of
my posts. I am sure they will contain something incriminating like
"Outlook Express" or worse.
__forceinline works pretty much in the same
way as the standard inline and only differs in the compiler not
performing the cost/benefit analysis it does for inline
functions/methods and a L1 warning being output whenever it
can't/won't inline.
No, I am not against compiler-specific directives/pragmas/tricks when
portability is not an issue.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 16 '07 #5
Victor Bazarov wrote:
Now, you probably already know that 'inline' is not a directive to
the compiler, but rather a hint, which the compiler is free to
ignore.
I thought 'inline' has completely lost its meaning of being a hint
to the compiler and has become exclusively a keyword for the linker.
It's like 'register' (except that 'register' doesn't mean anything
anymore, not even for the linker).
Aug 16 '07 #6
MiG
Juha Nieminen wrote:
I thought 'inline' has completely lost its meaning of being a hint
to the compiler and has become exclusively a keyword for the linker.
It's like 'register' (except that 'register' doesn't mean anything
anymore, not even for the linker).
I don't think so. I don't know how it works in other platforms but in
MsVC you can enable generation of _compile-time_ assembler output, which
allows you to see the inline expansion of functions performed by the
compiler.

Link-time optimizations can also be enabled but these, AFAIK, affect
only cross-module inlining.
--
Miguel Guedes
Aug 17 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
4
by: Ovidesvideo | last post by:
Just a quick question. If I declare functions in the class declaration as such: class myclass { public: void function(int &x) { x++; } };
6
by: Johs32 | last post by:
I get this warning: warning: incompatible implicit declaration of built-in function 'printf' because I use printf in a function that I include in a .h file that is included by other files...Do...
7
by: Ancient_Hacker | last post by:
In days of old, for no discernible reason, many CPU's had the ability to execute one or more instructions out of registers. Not very common today. Which brings up a semi interesting point. ...
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
14
by: jg | last post by:
Does C++ standard require an inline function be generated all the time ? For example, #include <iostream> using namespace std; inline int foo() {
12
by: aaragon | last post by:
I have this scenario: several arrays for which I have their fixed values at compilation time. Now, at runtime I need to access a specific array depending on an integer but I want to avoid if and...
15
by: Mahesh | last post by:
Hi, I need to know if stack frames are generated in case of a inline function execution or do they execute just like macros? if they execute like macros, then what is the need for having inline...
21
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.