Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?
A lot depends on how you write your C++ code.
As a baseline, you could write your program just like you would in C but
compile it with a C++ compiler. The performance of C vs. C++ is a wash
here. Of course this may sound obvbious, but I think it is an important
point because in most systems, performance is only an issue for a subset
of the code. With C++ you can always fall back to C-style programming
in areas where your program needs the performance and where C++ style
code would lead to an unacceptable performance penalty.
For example, the iostream library provides a lot more power than stdio,
but it also tends to run slower. If this isn't critical to your system
performance, then iostream is worth learning/using. However I wrote one
program where logging was a significant part of the overall system
performance and using iostream was about 3x slower than fprintf(), so I
wound up using fprintf(). The decision to write the program in C++ was
still a good one since I benefited from many of the C++ mechanisms
throughout the rest of the program and only had to fall back to a more
"C-like" approach in this one instance.
C++ has quite a few features (const, inline functions, templates) that
afford better abstraction than C, but when used properly, result in no
performance penalty.
There are a few instances (exceptions, virtual functions) where the
resulting code is usually more efficient than what you would've written
yourself in C - provided you needed the functionality. For example,
exceptions are often more efficient than explicit error checking, but if
your C program wasn't going to check errors, then exceptions aren't
helping you. Same with virtual functions versus switch statements or
explicit function pointers.
With the complexity and power of C++ comes a lot of potential for
problems - especially performance wise. This can be a real concern for
a performance sensitive project staffed by people who are solid C
programmers but new to C++. My only advice would be to go ahead and use
C++, but be disciplined in what features you use. Don't make everything
a virtual function and create a deep object hierarchy just because you
can in C++. It would also be worth reading up on some common pitfalls
and optimizations for C++ ("Effective C++" by Meyers is an excellent
book on the subject).
Dave Baum