LWN.net Logo

Sometimes C++ is faster

Sometimes C++ is faster

Posted Jun 19, 2008 21:03 UTC (Thu) by pynm0001 (guest, #18379)
In reply to: Sometimes C++ is faster by cate
Parent article: Converting GCC to C++

> virtual function are a lot slower than the direct C equivalent.

How would you do in C then?  Because however it is, it can be done that way in C++.

More seriously though, you are saying that C++ does something like:

this->v_btl->virtual_call(params); right?

I would agree, but how would you do this any faster in C?  Recognize that you may not cast the
object pointer to a derived class, the compiler can't (necessarily) know that the conversion
is valid, and you could cast it in C++ if the programmer happens to know more than the
compiler.

i.e. if you were to do:

derived_virtual_impl(klass, params) in C, you could do:

obj->Derived::impl(params) in C++ and call the appropriate implementation directly.

Is there some neat-o technique I'm missing?


(Log in to post comments)

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds