This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Need Information about the comparision of C/C++ on a c167

Hi all,

I am looking for information's about the comparison of C with C++ (RAM and ROM and timing behaviour) for a c167.

Any Information is welcome.

Tanks

  • It's going to depend on your compiler and how you write your code.

    In general, C++ is designed to be every bit as efficient as C, and you don't pay a penalty for features you don't use.

    If you start using some of the newer features, such as virtual functions, you'll pay more. But then, you also asked for more capability from that function, and I think you'll find that the built-in virtual function is as (or more) efficient than rolling your own with tables of function pointers, case statements, etc. If you didn't need this sort of run-time dispatch, then you shouldn't declare the C++ function virtual in the first place, just as you wouldn't write that extra C code. Be sure to compare apples to apples.

    Areas that you might want to evaluate carefully:

    - The iostreams library on many C++ systems used to be fairly large, and indivisable in that you often got the whole thing when you only needed part of it. This made "Hello World" comparisons overly large. The vendors have had a few years to work on it since last I cared to look, so they've probably improved.

    - exception handling can be implemented in many different ways, and it took a few years and release cycles for most of the vendors to come up with efficient ways to implement it. I've actually had libaries get smaller and faster as a result of replacing layers of return-code checking with exceptions that just cut to the chase. But you'll want to pay attention to the quality of the exception handling implementation if you want to use this feature.

    - templates can be implemented and used such that they don't create code bloat. But sometimes they aren't. You might want to be wary of templated libraries, including the STL. (The STL also does lots of dynamic memory allocation, which is often problematic for embedded systems. You might wind up supplying a lot of custom allocators.) Templates aren't inherently bad, but they got a bad reputation thanks to misapplication.

    The last two features of course have no C equivalent, so there's not much comparison to be done.