B
ben
is it true that a function without an inline keyword never get inlined? If
not true when is it inlined or not?
ben
not true when is it inlined or not?
ben
According to the C++ standard, inlining is at the discretion of theben said:is it true that a function without an inline keyword never get inlined? If
not true when is it inlined or not?
ben
ben said:is it true that a function without an inline keyword never get inlined? If
not true when is it inlined or not?
ben said:Ok, now, under what circumstances should I flag the keyword inline? What are
the likely candidates for inlining?
[top-posting]
James Daughtry:
Ok, now, under what circumstances should I flag the keyword inline? What are
the likely candidates for inlining?
ben said:is it true that a function without an inline keyword never get inlined? If
not true when is it inlined or not?
ben
ben said:Ok, now, under what circumstances should I flag the keyword inline? What are
the likely candidates for inlining?
Peter Koch Larsen said:According to the C++ standard, inlining is at the discretion of the
compiler. It might thus inline a function that is not marked as "inline" and
it might not inline a function marked as "inline".
[...]
The purpose of inline for the user point of view is to avoid errors with
multiple definitions.
Teeny tiny functions that would otherwise be written inline if there
weren't a need for some form of genericity. Follow this link for a
detailed analysis of why to avoid inline until you know that it buys
you something:
http://www.gotw.ca/gotw/033.htm
Just Say 'No For Now'
- avoid inlining or detailed tuning until performance profiles prove the need
- corollary: in general, avoid inlining
James said:The inline keyword is a hint, just like register. The compiler is free
to ignore it entirely. As such, functions without an inline keyword (or
defined outside of a class declaration) may be inlined if it meets some
unspecified internal heuristics. How a compiler optimizes code is
implementation-dependent.
I would say that the GOTW supports my conclusion to the letter.
Obviously you're talking about some miniscule detail of my post, so
please let me know what it was so that I can be more detailed next time.
Ok, now, under what circumstances should I flag the keyword inline? What are
the likely candidates for inlining?
Teeny tiny functions that would otherwise be written inline if there
weren't a need for some form of genericity.
There is one important difference, though. If you *define* your function
in a header without declaring it 'inline' and then include that header in
more than one module, you break the ODR. If the function is declared
'inline', that doesn't happen even if the compiler does not inline it in
all the cases (and instead creates a body somewhere).
Victor said:There is one important difference, though. If you *define* your function
in a header without declaring it 'inline' and then include that header in
more than one module, you break the ODR. If the function is declared
'inline', that doesn't happen even if the compiler does not inline it in
all the cases (and instead creates a body somewhere).
Ioannis said:If you just want this, and you do not intend to inline, you can just
make the function static, and place its definition in the header.
If you just want this, and you do not intend to inline, you can just
make the function static, and place its definition in the header.
However why would someone want to place a function definition in a
header file?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.