Choosing C, or C++?

JumpStart C++ for Cortex is ImageCraft’s first compiler product that supports C++. It does this by leveraging the GCC compiler instead of ImageCraft's own C compiler. A natural question that may come up is: should a user write in C or C++? The choice is up to the individual’s needs. Here are some factors to consider. Basically, it comes down to: if you are concerned about “C++ overhead”, start with “mostly C”, and only add C++ features as needed and as you understand the tradeoffs better. However, it is easy to intermix C and C++ source files in the same project, see below.


C++ may generate significantly larger code, but not necessarily. This is a common complaint about using C++ in embedded systems. Some C++ features (e.g. virtual functions, default constructors and destructors, etc.) definitely contribute to larger code. On the other hand, by replacing that code with C code with similar semantics, you may not see much of a difference.


C++ is more difficult to use. The biggest issue with C++ is that it’s now really an aggregate of multiple languages with support for multiple programming paradigms. Indeed, some will go as far as to say that no single person ever fully understands all of C++[1]. As an example, C++ templates, which basically allow compile-time computation, were found to be Turing-Complete after they were proposed and designed.


Instruction timing for C++ functions are harder to determine. As an example, in the simplest case, in C, a ‘+’ operator means that at worst (timing-wise) it is a floating point addition and the execution time for that expression is bound by that. However, in C++, with operator overload, a  ‘+’ “operation” may actually mean a complex matrix addition, which would require a lot more code and time to execute. Now, with even newer features such as inheritance, virtual functions, templates, etc., it’s not possible to estimate the runtime of an arbitrary C++ code fragment.


JSAPI (V9) uses C++. ImageCraft’s JumpStart API (JSAPI, described later) was originally implemented with enhanced C[2] in ImageCraft's JumpStart C for Cortex-M product. In JumpStart C++ for Cortex, JSAPI V9 is implemented using C++ class features. Therefore, if your program makes use of JSAPI V9, then the code that uses JSAPI must be written in C++. However, it is easy to intermix C and C++ source files in the same project, see below.