In a recentblog, a new embedded systems developer asks for advice about whento use C and when to use C++. This question captures the dilemma that eventhe most experienced embedded system programmers face at some point. Theresponses to his blog question in general suggest using the two in combinationon an as needed basis, selectively using features that help you and ignoringthe ones that give you problems.
While such an in-between solution may be appropriate in traditional deeply embedded 8-, 16-, and 32-bit MCU designs, several trends may force developers to leap with both feet into the C++ camp. For one thing, there are the many embedded consumer and network designs created by teams of developers with millions of lines of code that need the sophisticated object-orientedand reuse features of C++.
And then there is the shift to the use of C++ or a variant in multicore programming. In addition, in systemlevel SoC circuit design t here is the increasing use of C++ extensionssuch as SystemC to mimic the parallel operations inherent in such gate levelHDLs such as Verilog and VHDL. Finally, in a variety of industrial wirelessM2M and sensor apps, MCUs will be interfacing to enterprise servers and networks,where C++, and not C, is the programming language of choice.
A number of recent design articles and white papers in this issue ofthe newsletter will help you make informed decisions about C++, and onceyou have made the shift, they will help you learn more about this more complicated – and more powerful – extension to C. A particular favorite of mine is “Dive in to C++ and survive.”
I have also included some columnsfrom Dan Saks, who has waged a decade-long struggle to bring C++into the mainstream of embedded systems programming.
Good reading!! Let’s hear from you on line at Embedded.com or by contacting me directly with your ideas and responses. (EET/Embedded.com Editor Bernard Cole, firstname.lastname@example.org, 928-525-9087 )
Design How Tos
Making the transition from C to C++
Although it has taken almost a decade, the transition from C to C++ is now gaining momentum in many complex software projects, in parallel programming for multicore apps and in hardware generation environments. Here's a three step strategy for making the transition and migrating code from C to C++.
Dive in to C++ and survive
Programmer Christopher White guides you through the hazards of learning the ins and outs of the C++ language, the books to read, the tools to use and how to begin using it effectively in your embedded systems designs.
Transitioning from C/C++ to SystemC in high-level design
It's far easier to do architecture design in SystemC than it is to do it in C and C++. If co-designing hardware and software using high-level design methods, much of your work will be done in an architecture design phase in SystemC. Here's why.
Moving beyond C-language development with MISRA C++:2008
The new standard MISRA C++:2008 contains important protections for the use of the C++ language and is worth inspecting for suitability in your development environment, whether embedded or system, and whether safety or mission-critical in nature.
PRODUCT HOW-TO: Using the MISRA C++ language subset in your application
How the MISRA C++ language subset can mitigate insecurities within the C++ language and how the LDRA tool suite can be used to demonstrate compliance.
Guidelines for using C++ as an alternative to C in embedded designs: Part 1
In this two part tutorial, Colin Walls addresses the well-known barriers to use of C++ by C programmers, and provides some guidelines including cleaning up C and an in-between alternative he calls “C+.” First up: Why is C++ not more widely used?
Using object-oriented methods to achieve C++'s promise: Part 1
A professional programmer and teacher explains why C++ and its promise of reusability, portability and scalability has not been the hoped-for Magic Bullet that would eliminate code inefficiencies.
Guidelines for writing efficient C/C++ code
Greg Davis of Green Hills explains the details of programming with modern compilers and how to get good performance using the right choice of data types, variable scopes, the restrict keyword, floating point arithmetic, assembly statements, packing, and loop optimizations.
Delivering the benefits of C++ encapsulation to your embedded design
C++ can deliver real benefits to an embedded design, particularly when “encapsulation of expertise” is used.
Building portable systems in C++
C++ covers the whole programming range, from low level to high, making it ideally suited for writing portable software. Code portability is often neglected in embedded-systems engineering, however. With software becoming increasingly complex, and hardware becoming more interchangeable than ever, this oversight can turn into a problem when software must be ported to a new platform. What follows are some tools and techniques that can be used to design and build portable software in C++.
A six step process for migrating embedded C into a C++ object-oriented framework
Using a standard timer, Dirk Braun describes a six step process to migrate embedded C code into a C++ object-oriented framework and create classes that represent a type of on-chip hardware peripheral.
A guide to C++ for the cautious embedded programmer
Approached in the right way, the C++ language has many benefits to offer the embedded software developer. Here are some brief guidelines in its use, highlighting areas of good practice ” things to do and things to avoid.
GrammaTech CodeSonar and Lattix LDM integration enhances architecture management for complex C/C++ systems
GrammaTech, Inc. and Lattix Inc. have teamed to integrate GrammaTech CodeSonar and Lattix LDM. The new CodeSonar integration with Lattix provides precise and accurate architecture analysis to enable teams to review, refactor and maintain the architecture of complex C/C++ software systems.
SOFTWARE TOOLS: Intel updates its concurrent C/C++ tools
Concurrent Collections Release 0.3.0 includes improvements in performance and memory usage
Synfora adds C++ support to PICO HLS tools
Synthesis tool vendor Synfora Inc. announced it has extended support for C++ language in its PICO Extreme and PICO Extreme FPGA C synthesis tools.
Version 2.4 of RapiTime supports C++
Rapita Systems' latest version of the RapiTime measurement and analysis tool now includes C++ support. Version 2.4 is Rapita's response to the growing use of C++ by engineers and managers developing applications for critical real-time C++ embedded systems.