C++ – more Questions and Answers
Following on from my recent online C++ lecture series, I found that I had a lot of interesting questions from the audience, which I had limited time to answer. It seemed logical to do so here. So this is the first of a number of posts where I will address one or more of these questions. If you have any questions about embedded software [not just C++], please email me and I will do my best to answer them.
For today, there are just 3 C++ related queries …
For what kind of embedded applications is C++ suitable?
Given the availability of suitable tools for the chosen target, almost any application could be efficiently coded in C++, as there should be no more overhead than doing the job in C. However, the true benefits of using the C++ language are more apparent in a larger project, where there may be significant number of developers working on the code.
Does “mangling” occur after compiling?
This question refers to the process whereby C++ function names are modified in order to make them unique with respect to the number and type of the parameters. This facilitates function overloading and typesafe linkage, where the link will give an error if the definition/declarations and usage of a function do not match across translation units.
To answer the question: No, mangling occurs during compilation as the compiler builds the symbol table. As all functions must be prototyped in C++, it is when the prototypes are read that the compiler creates the mangled name. As it finds calls to functions, their names are mangled and the absence of a matching prototype results in a compile time error.
Are all C keywords recognized by C++?
The simple answer to this question is: kind of yes. As the two languages are developing in a somewhat independent manner, this may not always be the case. It should not matter to a specific developer, as they should have a thorough grasp of the dialect of the language they are using. It is important to use a naming convention for variables, constants, classes etc. which is not simply lower case letters, thus avoiding any possible clash with keywords. One particularly interesting example is the keyword auto, where it means something entirely different between the two languages.
I acknowledge input from my colleague Jon Roelofs who put me right on a few points.
Posted June 16th, 2014, by Colin Walls
- Choose your weapons – options for debugging
- Dissatisfaction, customer service and surprises
- Video blog about getting into embedded software
- Embedded software article: RTOS Revealed #9
- Lost in translation
- One return from a function: a good idea?
- The A380 experience
- Embedded Software Masterclass
- How to get rich