Modern languages have
another go at unseating C
Can Modern C++ and Rust convince embedded developers to switch? Chris Edwards investigates
The world of embedded systems
programming is littered with
the remains of languages that
promised to be better than C but,
for whatever reason, failed to gain
traction.
If you take a look at Barr Group’s
annual survey of language use in
embedded, C continues to enjoy a
commanding lead, used by close to 70
per cent of respondents. Remarkably,
usage of C++, which was created a
decade after C, apparently peaked in
2006 before dropping back to around
20 per cent, though its penetration
has increased slowly since the middle
of the current decade.
Inertia is one reason for the
seemingly slow pace of change.
Anders Holmberg, chief strategy
officer at IAR Systems says: “There’s
so much code out there written in C
that nobody really wants to rewrite
in another language, as that will risk
introduce new bugs into the code
base. So even if a design in updated
with new features, the code base is
very likely to still be C.”
Another thing that C has had in
its favour is the ubiquity of tools that
support it. Today, no-one attempts to
launch a microcontroller architecture
without some kind of C compiler,
build and debug support. However,
circumstances are changing that are
easing the switch to other options.
Holmberg points to the increasing
use of operating systems such
as Windows, Linux and Android in
embedded, where development
tends to favour C++. This tends to
push teams towards C++ in order to
maintain a common code base for
the bare-metal or RTOS-based code
as well. “This trend is partly driven by
the fact that most cross-compilers for
embedded, at least the ‘big names’,
now solidly support C++14 and often
most of C++17.”
The migration could go further
by a trend in toolchain design to
make compilers more modular. The
prime open-source example of that
is the Low-Level Virtual Machine
(LLVM) toolchain which has been
embraced by companies such as Arm
and, more recently, Wind River. As
well as supporting recent iterations
of C++, Michel Chabroux, senior
director of product management at
Wind River, points to LLVM as being
instrumental in the company’s ability
to support C alternatives, such as
the Rust language, as well as making
it easier to run prototype code on
a development host through the
WebAssembly intermediate format the
compiler can generate.
One big advantage of Rust
claimed by its advocates is that it
streamlines for the programmer the
way dynamic memory allocation is
handled compared to C or C++ without
resorting to the garbage-collection
strategies used by Java or by Go,
another C-like language from the
world of cloud computing. Without
garbage collection, there is no need to
periodically halt the runtime to search
for memory to clean up.
Rust enforces checks on how
memory is allocated and accessed
at compile time that. In principle,
20 14 January 2020 www.newelectronics.co.uk
Michael Traitov/stock.adobe.com
/www.newelectronics.co.uk
/stock.adobe.com