Thought Leadership

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.

Colin Walls

I have over thirty years experience in the electronics industry, largely dedicated to embedded software. A frequent presenter at conferences and seminars and author of numerous technical articles and two books on embedded software, I am a member of the marketing team of the Mentor Graphics Embedded Systems Division, and am based in the UK. Away from work, I have a wide range of interests including photography and trying to point my two daughters in the right direction in life. Learn more about Colin, including his go-to karaoke song and the best parts of being British: http://go.mentor.com/3_acv

More from this author

Leave a Reply

This article first appeared on the Siemens Digital Industries Software blog at https://blogs.sw.siemens.com/embedded-software/2014/06/16/c-more-questions-and-answers/