Using C++ in GCC is OK
Larry Evans
cppljevans@suddenlink.net
Fri Jun 4 14:20:00 GMT 2010
On 06/03/10 14:39, Steinar Bang wrote:
>>>>>> Larry Evans <cppljevans@suddenlink.net>:
>
>> claims that switch statements are faster than virtual function calls.
>
> That's not really interesting, is it? The overhead and downsides of
> virtual functions are well known.
>
> The upside is the possibility to use polymorphism to make frameworks.
> All kinds of pluggable frameworks.
>
> And as polymorphism goes, virtual functions are pretty cheap.
>
>
Agreed; however, according the the 2nd link I provided:
http://lists.boost.org/Archives/boost/2008/01/132074.php
apparently speed is more important, and the 1st link:
http://sourceforge.net/mailarchive/message.php?msg_name=3f49a9f41003031715g19a23b94p47ccec2251acd55%40mail.gmail.com
suggested that the author had experienced problems with
using switch vs virtual functions:
> P.P.S. Yes, the design you are using is a sore spot for me, I was bit
> with such things many years ago, it is one of my quests to educate
> people about the better ways now.
>
I'd had some experience with compilers written in c++ that had large
switch statements and wondered why the authors hadn't used virtual
functions. IOW, I believed as you do; however, OvermindDl1's post
caused me some doubt. I even checked clang's code to see if they used
switch's or virtual functions and was surprised to learn they used
switch's:
http://llvm.org/svn/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp
(in particular, the CFGBuilder::Visit function).
Hence, I figured there must be something I'm missing
about the pros and cons of switch's vs virtual functions.
-regards,
Larry
More information about the Gcc
mailing list