Joseph S. Myers wrote:

> I repeat my request from the RM Q&A for a guide for reviewers on how to 
> detect hidden overhead in the presence of C++ features.  When will a 
> structure/class/union be larger than might be expected in C?  When will 
> C++ statements involve runtime overhead that might not be expected from 
> equivalent C statements?

I think you're being unnecessarily fearful.

A C++ structure/class/union will be larger than the same data structure
written in C iff (a) it uses virtual functions, (b) it uses virtual
inheritance.  The former adds exactly one pointer to the very beginning
of the structure, independent of the number of virtual functions, and
even if there is (non-virtual) inheritance.  The latter is forbidden by
Ian's proposed coding standards.  So, you do indeed want to avoid
virtual functions in small, plentiful objects, as it can make them much
bigger.

Statements in the C subset of C++ have the same performance they would
in C.  (I'm sure someone can come up with an exception, but it will be
vanishingly rare.)  In C++, you can of course make what looks like
simple code do something expensive; for example, you can make "a + b" be
arbitrarily complex if "a" and "b" are instances of class types and you
have overloaded "+".  But, if you just recompile your C program as C++,
it doesn't suddenly get significantly bigger or slower.

-- 
Mark Mitchell
CodeSourcery
m...@codesourcery.com
(650) 331-3385 x713

Reply via email to