By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,997 Members | 2,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,997 IT Pros & Developers. It's quick & easy.

Function declarations and inline

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.