C vs. C++ with ARM C/C++ Compiler

#1683214
Rate this post
useful
not useful
I have no experience regarding ARM, but the impact of
C++ may be nearly 0 in some cases or frightening in other cases.

It depends on which featrures of C++ you want to use.

C++ is nearly a superset of C, so you can program C++ like C
with no additional overhead.

Cautious use of templates may be very useful with no overhead.

Virtual methods should be checked.

std::strings are clearly more expensive than zero terminated
strings, and so on.

There will be no easy way to calculate the additional
resources in general.
#1684069
Rate this post
useful
not useful
Hi Klaus,

thanks for your input.

I have attended a talk at the Embedded World 2010 in Nuremberg about 
this topic, but specific to the IAR compiler. The speaker categorized 
the overhead (in terms of footprint) for the various features of C++ as 
free, cheap and expensive. The following list shows the conclusion:

• encapsulation/classes - FREE
• namespaces - FREE
• inlining - FREE
• operator overloading - FREE
• constructors/destructors - FREE
• references - FREE
• virtual functions - CHEAP
• templates - EXPENSIVE
• STL (Standard Template Library) – EXPENSIVE
• RTTI – expensive
• exceptions - expensive

What is missing in the list are dynamic and reinterpret casts. I fear 
these would be expensive too.

As I see, your experience with templates is different from what IAR 
states. Virtual functions might cause increasing overhead in deep 
hierarchies I guess (vtable gets more entries).

Nevertheless, the above list only tells me how the IAR compiler deals 
with the features. Since I am using the ARM Real View Compiler, figures 
on this would be great.

--
Regards,
 Marco
Guest #1684159
Rate this post
useful
not useful
> What is missing in the list are dynamic and reinterpret casts.
> I fear these would be expensive too.

Dynamic casts are expensive, because they need RTTI.
Reinterpret casts should be free, they are just a way to circumvent the 
type system.
#1684295
Rate this post
useful
not useful
ACK

Note: I do not agree with "templates - EXPENSIVE" in general.
Templates have no overhead compared with the same
functionality written as usual functions or methods.

Templates become expensive (in terms of generated code) when
they are instantiated more than one time - but again not more
expensive than normal functions written in as many variants.

The only problem while using templates is the fact that
the programmer may be not aware of how many instances of a
template he produces simply by using the templates.

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now