Re: C vs C++ in Embedded Systems?

From: Steven R. Wheeler (swheeler843_at_earthlink.net)
Date: 01/29/05


Date: Sat, 29 Jan 2005 11:33:59 -0700

Tim Wescott wrote:
> Grant Edwards wrote:
>
>> On 2005-01-28, Mayank Kaushik <prehistorictoad2k@yahoo.com> wrote:
>>
>>
>>> How do C and C++ compare vis-a-vis Embedded Systems?
>>
>>
>>
>> IMO, nobody should write a line of source code for an embedded
>> system unless they know ahead of time what code (more or less)
>> the compiler is going to generate. That's possible with C.
>>
>> The C++ language is so unbelievably complex and "feature"
>> ridden, that nobody ever quite knows what's going to happen
>> when they write a line of code.
>>
>> IOW, I don't approve of C++ for embedde use. Or for
>> non-embedded use, actually.
>>
> Yes on paying attention to compiler output, no on C++ paranoia.
>
> As long as you avoid the really dippy language features and don't touch
> the C++ standard libraries with a 10-foot pole you'll do OK. Most
> compilers only pull in the extra baggage for a feature if you use it, so
> if you don't use the feature you're OK. And if you have a compiler that
> _does_ pull in the baggage then don't use it!
>
> I've been programming headless embedded systems in C++ for eight years
> now with great success. It enables faster programming on large
> applications, easier factoring of jobs among a team, and significantly
> easier design-for-reuse. It _does_ require careful programming, and an
> idiot at the keyboard will bring you down faster than anything, but you
> get that with any programming language.

I'll agree with the "idiot at the keyboard" comment, but disagree on not
being paranoid about C++. Paranoia doesn't mean "don't use it ever," it
means "be concerned/afraid/careful."

This is a subject that comes up from time to time. One of the previous
times, I printed out a comment in the thread, just because it had very
good information about _why_ you should be paranoid about C++ in
embedded systems. It was written by Jonathon Kirwan, and he called it
"My World and Welcome To It." I've kept it around since then, because I
work on similarly small systems, but I'm starting to do more with
32-bitters and need to know about C++ since our customers ask for/about it.

You can find Mr. Kirwan's post here:
http://groups-beta.google.com/group/comp.arch.embedded/browse_thread/thread/36d06d841b7c8422/8c402e042e26d771?q=kirwan+%22my+world%22+C%2B%2B&_done=%2Fgroups%3Fq%3Dkirwan+%22my+world%22+C%2B%2B%26hl%3Den%26lr%3D%26tab%3Dng%26ie%3DUTF-8%26sa%3DN%26&_doneTitle=Back+to+Search&&d#8c402e042e26d771

-- 
wheels


Relevant Pages

  • Re: C vs C++ in Embedded Systems?
    ... nobody should write a line of source code for an embedded ... Yes on paying attention to compiler output, ... if you don't use the feature you're OK. ... I've been programming headless embedded systems in C++ for eight years ...
    (comp.arch.embedded)
  • Re: Bounds checked arrays
    ... > Nobody is perfect. ... case the compiler is progammed by humans. ... I would not support this proposal with the #pragma ... If the source file was modified, ...
    (comp.lang.c)
  • Re: How to Make F77 Program Faster (g95 compiler) ??
    ... Richard Maine wrote: ... semantics of the code than by trying to help the compiler to do a better ... I'm surprised that nobody else mentioned that previously in this thread, ...
    (comp.lang.fortran)
  • Re: Policy for removing working code
    ... progress dictates we need fix/maintainership to feature X ... -> nobody responds ... So, get to work, become a committer, get elected to core and have a control over ... to be core@ member to predict this policy will eventually harm FreeBSD ...
    (freebsd-stable)
  • Re: c to c++
    ... something is true in 98% of cases, nobody, or almost nobody, cares if ... where a C++ compiler gets angry while a C compiler says ... cares pedantic or strictly accurate definitions, ... pratical superset of C if it is trivial to get a large body ...
    (comp.lang.c)