Andrew: Hi. I'm here today with Dan Smith, Barr
Group principal engineer to talk about
embedded C++ . So Dan, clearly C is the
predominant language that is used in
embedded systems. Why is C so popular in
embedded systems?
Dan: Yeah that's a good question. Yeah,  first thing I'll
say is that if people are wondering as
far as statistics and data from our
Embedded Systems Survey that we do every year
and from training, I always ask the
question who is using C and who is using C++
It's pretty clear it's an 80 - 20 split
85 - 15 split. Most people are using C; some
people are using C++. So it is dominant.  And I have pretty good
intuition on that from talking to people,
and I've had people tell me it is
typically due to the fact that a lot of
people who come in to embedded
programming are coming from a EE
background or a computer engineering
background. And way back in the early
days when they're first learning, those
classes are typically taught using a C
programming language.
Andrew: True.
Dan: It's kind of, you know, C is kind of a high-level
assembly language for all intents and
purposes. And by the way, I'm never going to
say anything bad about C. I love the
language but it does have its sharp edges.
Andrew: it has its limitations, it's issues.
Dan: Exactly, it does. But we as embedded engineers
wanted to use it. So predominantly, I
believe the reason is that is what people
learn is that is what people stick with
and they learn to solve their problems
using C. So they don't really find a need
to go looking elsewhere for something
else.
Andrew: Okay. But like you said, you know in
our recent Embedded Safety and Security
survey, 20% are using embedded C++.
So clearly there are motivations and
reasons to use it. What are the primary
reasons why someone might use C++ or
wanting to use C++ in their embedded project?
Dan: Right, right. Well, you
know so C++ is traditionally regarded by
a lot of deeply embedded developers as a
desktop language because that used to be
the predominant domain for C++. It's only
for desktop applications but it's being
used more and more in embedded work. And
one of the main reasons for using C++ is
that we like to say it gives you a
bigger toolbox.
So the language itself it is a bigger
language.
Andrew: Right.
Dan: It's not exactly a superset of C, that's not quite a correct way to
characterize it, but
it largely is. But it does give you a lot more things out of
the power out of the box.
So people like to say batteries included.
Andrew: Right
Dan: And so you could be productive and more quickly.
I don't have time to get into all those
right now but that's an overarching
answer. There are also some things
that you can do using C++ that you
actually cannot do in the C programming
language due to features like templates
or the magic of constructors and
destructors which run automatically.
You don't have to write them and you can't
forget to write them. And you can also
tailor C++ for an embedded system to
make it smaller. There's a saying in the
embedded systems, -  or really in
the C++ community that you only pay for
what you use. So a lot of people believe
that C++ is big and bloated but that's
not necessarily the case.
Andrew: Right.
Dan: So yeah those
are the main reasons that people are
using C++ than embedded, and I think the
percentage is slowly growing.
Andrew: So the - some of those features of C++ that may
may result in slower execution times or
more memory usage of things like that,
you can choose to avoid using them and
use those features of the language that
will benefit you without necessarily
having to pay the price of using some of
the features that might be fine for C++ in
desktop or a cloud-based computing but
embedded computing are not.
Dan: Yeah, that's exactly right. Either by just not using
the features and therefore they're now
built in your executable, or by
explicitly disabling them at compile
time and link time such as exceptions
and runtime type information. Those are
two features which are almost always
disabled in embedded systems.
Andrew: Because of the impact they would have on the performance and the cost of the system and all that
Dan: Yeah
Andrew: Okay and are there certain types of projects
or efforts where C++ is kind of a better
fit than C in terms of embedded systems?
Dan: So I would say that C++ is almost always
a good fit as long as the people in the
group understand the language and can
use it but as far as where I would say
where I see it most
widely is, there are usually two
factors. One is as a project gets larger
and larger the benefits of some of C++'s
features like name spaces and, you know,
perhaps templates and other things which
we won't get into, they really start to
shine in a bigger project. And so I see
it typically used in bigger projects, not
to say it's not applicable on smaller
project.
Andrew: Right
Dan: And then I also see it used in
projects where the project leader
perhaps is very strong in C++ and knows
how to use it properly and once they
agreed into the group because it is a good
fit even if it's not a big project but
that person knows that he or she can
shepherd the usage of the language
properly keep it from getting out of
control and develop a good  use. So if
one of those two factors is at play or
both, that's when I intend to see the use.
Andrew: Okay great
great any of any closing thoughts?
Dan: The only thing I'll say, actually two
different points. One is we do have a
webinar at Barr Group on C++. A colleague,
Michael Wilk did a very good webinar a
few months ago on that. I think
that's available to go through our website
Andrew: That's our website, sure.
Dan: Okay great
and I would totally recommend anybody
to watch that video if this is interesting.
And then the other thing is that both in
our Embedded Software Boot Camp and in our
Embedded Security Boot Camp, we discuss usage
of the language. Particularly in the
security boot camp, we actually have two
hands-on exercises that use specific
features of the language that you can't
do in C that it improved the security of
your software. So, I think that's a good
compelling reason to use it. And that's in
our security boot camp.
Andrew: Okay great well. Thank you, Dan.
Dan: You're welcome
