|
|
virtual inline
if you have
class Base {
virtual inline bool foo() {return false;};
};
class Derived: public Base {
virtual bool foo();
};
bool Derived:foo()
{
/* lot's of code here */
return true;
};
is foo() always inlined for Base? is foo always (jumped /
called / ...) (<-?) for Derived?
|
|
0
|
|
|
|
Reply
|
clqrq (66)
|
11/14/2008 5:50:25 PM |
|
..rhavin grobert wrote:
> if you have
>
> class Base {
> virtual inline bool foo() {return false;};
> };
>
> class Derived: public Base {
> virtual bool foo();
> };
>
>
> bool Derived:foo()
> {
> /* lot's of code here */
> return true;
> };
>
> is foo() always inlined for Base?
What does that mean?
> is foo always (jumped /
> called / ...) (<-?) for Derived?
What does that mean?
A function cannot be "always inlined" or "never inlined". You have no
control over that - the compiler is free to do what it thinks is best,
neither do you have any way of knowing what the compiler did - there is
no portable way to determine if a particular function was ever inlined
or not. Why do you care?
The concepts of dynamic binding (virtual functions) and inlining are
orthogonal. If the compiler knows that it needs to call 'Base::foo' and
it has the implementation handy (and it's short like that), it will
*probably* (or, perhaps, *hopefully*) inline it. If the compiler needs
to involve run-time resolution (i.e. it has a pointer or a reference to
'Base' and calls 'foo' with that), it will generate code to call the
function in a particular way (v-table, etc.) and "inlining" has nothing
to do with that.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
|
|
0
|
|
|
|
Reply
|
v.Abazarov (13255)
|
11/14/2008 5:57:43 PM
|
|
On 2008-11-14 12:50:25 -0500, ".rhavin grobert" <clqrq@yahoo.de> said:
> if you have
>
> class Base {
> virtual inline bool foo() {return false;};
> };
>
> class Derived: public Base {
> virtual bool foo();
> };
>
>
> bool Derived:foo()
> {
> /* lot's of code here */
> return true;
> };
>
> is foo() always inlined for Base? is foo always (jumped /
> called / ...) (<-?) for Derived?
Ask your compiler. There's no requirement that inline functions be
expaned inline.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
|
|
0
|
|
|
|
Reply
|
pete2666 (1733)
|
11/14/2008 5:58:15 PM
|
|
Hi!
..rhavin grobert schrieb:
> class Base {
> virtual inline bool foo() {return false;};
> };
>
> class Derived: public Base {
> virtual bool foo();
> };
>
> bool Derived:foo()
> {
> /* lot's of code here */
> return true;
> };
>
> is foo() always inlined for Base? is foo always (jumped /
> called / ...) (<-?) for Derived?
From your code Base::foo is never called at all, so you cannot answer
the question whether it is expanded inline or not.
Derived::foo cannot be expanded inline unless your compiler uses a two
pass method to examine the body of the function.
Furthermore, a virtual function may not be expanded inline unless the
compiler knows for sure, that it cannot be overloaded. The reason is
simply that the required function is determined at runtime and may not
even be written at the time when the compiler generates the call.
Only if the type is known for sure, the run time dispatch can be
optimized. E.g.
Base b;
b.foo();
may expand Base::foo inline.
But as soon as b becomes a reference or pointer type, a run time
dispatch is required.
(Languages with a 'final' attribute for functions and classes have a
significantly higher probability of the above optimization.)
Marcel
|
|
0
|
|
|
|
Reply
|
news.5.maazl2 (236)
|
11/15/2008 9:49:13 AM
|
|
On 2008-11-15 04:49:13 -0500, Marcel Müller
<news.5.maazl@spamgourmet.com> said:
>
> Furthermore, a virtual function may not be expanded inline unless the
> compiler knows for sure, that it cannot be overloaded.
Overloading has nothing to do with it.
> The reason is simply that the required function is determined at
> runtime and may not even be written at the time when the compiler
> generates the call.
This is not overloading. It is overriding.
> Only if the type is known for sure, the run time dispatch can be
> optimized. E.g.
> Base b;
> b.foo();
> may expand Base::foo inline.
> But as soon as b becomes a reference or pointer type, a run time
> dispatch is required.
No, not required. Just quite common. But if the compiler can determine
the actual type of the object it can expand the function inline.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
|
|
0
|
|
|
|
Reply
|
pete2666 (1733)
|
11/15/2008 12:58:34 PM
|
|
On Nov 14, 10:50 pm, ".rhavin grobert" <cl...@yahoo.de> wrote:
> if you have
>
> class Base {
> virtual inline bool foo() {return false;};
>
> };
>
> class Derived: public Base {
> virtual bool foo();
>
> };
>
> bool Derived:foo()
> {
> /* lot's of code here */
> return true;
>
> };
>
> is foo() always inlined for Base? is foo always (jumped /
> called / ...) (<-?) for Derived?
For more information visit this link:
http://groups.google.com/group/CPP-newsgroup/web/standard-c-programming-virtual-functions-and-inlining-virtual-functions-and-inlining?hl=en
--
Daya
|
|
0
|
|
|
|
Reply
|
mail.dsp (14)
|
11/17/2008 8:25:41 AM
|
|
|
5 Replies
30 Views
(page loaded in 0.131 seconds)
Similiar Articles: Use Ring0 mode in Visual Studio .NET - comp.lang.asm.x86 ...They have no meaning in Windows except for the Virtual DOS Machine. You can install ... > I'm using inline assembly in Visual Studio .NET, to make programs that use > DOS ... Tcl Expect ssh to shutdown Linux box - comp.lang.tclHi, I am trying to shutdown down a Virtual machine by ssh'ing into it via Tcl ... sg332 wrote: > Hi Uwe, > Please see inline preceded by [sg332_2] > > Also, it ... ftgl linker problems - comp.graphics.api.opengl... are missing eg: >glfont.obj : error LNK2001: external simbol "public: virtual class ... generic BBox() implementation */ template <typename T> inline ... ip accounting on cisco 3550 switch - comp.dcom.sys.cisco ...... can I assign 2 IP address to a Cisco 2950 running flash ... We are using inline ... phone with Cisco CME 3.3 - comp ... Cisco 2950 Issue - comp.dcom.sys.cisco... virtual ... Swing uses bad features - comp.lang.java.guiSo we are talking about "normal" virtual dispatch, not the more complicated mechanism ... Otherwise, if the containing method is executed frequently: Inline the call to ... iA32 Paging - comp.lang.asm.x86Here is what I think I know: A Virtual Address is split up into 3 parts 10 bits ... c program into assemble as follow ... iA32 Paging - comp.lang.asm.x86 icc inline ... copy a file while it is actively being written - comp.os.linux ...In other words, test that your virtual machines' performance remains acceptable ... > Shi > Note: comments inline. IMO, you're going to have to run some tests to ... const member functions in classes derived from templates. - comp ...... return size; } > }; > > class B : public A<1> { > public: > B(): A<1>() {} > virtual ... Get rid of unused parameter warning? - comp.lang.c++ template<typename T> inline ... x86-64 and calling conventions - comp.compilersEach function is to compile to also use virtual registers rather than real ones. ... Oh, yes, the decision as to whether to inline small functions will happen at the ... LSA Disk Sector Read - using int 13h ah 42 (extended read) - comp ...I'm doing C > with inline ASM. > Note: I called check_extensions and extension are ... Both will need to be copied from a virtual address above 1Mb to a physical Real Mode ... C++ Q&A: Inline Virtual Functions, AVI Files in EXEs, and the ...Of course you can't do this because val is private. Inline functions give you the advantage of data hiding without paying the price of a function call. c++ - Are inline virtual functions really a non-sense? - Stack ...I got this question when I received a code review comment saying virtual functions need not be inline. I thought inline virtual functions could come in handy in ... 7/27/2012 9:41:15 PM
|
|
|
|
|
|
|
|
|