C or C++ for embedded system plug-in?

R

Randy Howard

We made very good experience with C++ on embedded systems even for time
critical tasks.

For our system we restricted the C++ features that are allowed. Those
are:
- no dynamic memory allocation (no new, delete, malloc, free etc.)
- no exceptions
- no run time type information
- no virtual functions
- no templates

So why use it?
The resulting software is very modular and and code is easy to read. We
almost never had any of those typical C memory access errors...

Strange, I use C instead of C++ and don't have "typical C memory access
errors". What are you referring to, specifically?
The great benefits of C++ over C in this projects are:
- excessive usage of references instead of pointers makes the code very
robust

How does it make it more robust? Do you really mean that it helps
programmers who don't know C and pointers very well?
- excessive usage of const classifiers avoids mis-usage of objects

Is it excessive, or not? :)
- class access rights + lightweight inline methods (set, get) assure
protection of internal module variables. Old projects were full of
those evil extern declarations...

Ah, so you don't have C-literate programmers. You might want to
investigate how ADT's are properly implemented in C.
One of the disadvantage of C++ is a slightly greater memory footprint
because C++ environment initialization is more sophisticated...

That's ok, embedded platforms always have plenty of memory. :)
I really like the beauty of our lightwight wrappers for hardware
interfaces. Almost no runtime-overhead, intuitive usage, and very
robust against abuse at the same time.

Who "abuses" embedded software, other than the implementor(s)?
Much better than anything that you can achieve in C.

Not true. Perhaps you meant to write "I" instead of "you".
 
L

Lionel B

So why use it?


Strange, I use C instead of C++ and don't have "typical C memory access
errors". What are you referring to, specifically?

I suspect he meant such things as attempting to dereference a pointer to
NULL or to the "wrong" area of memory, forgetting to deallocate memory
(memory leakage), reading/writing past the end of an array or memory
buffer, ...

C++ does have mechanisms lacking in C to assist in avoiding these errors,
such as the ability to do memory allocation/deallocation in
constructors/destructors, overloading of operators to implement array
bounds checking and ...
How does it make it more robust? Do you really mean that it helps
programmers who don't know C and pointers very well?

It is possible, but you have to be almost wilfully perverse, to initialise
a reference with a NULL/invalid address.
Is it excessive, or not? :)

Perhaps "consistent usage wherever appropriate" might have been a better
phrase :)
Ah, so you don't have C-literate programmers. You might want to
investigate how ADT's are properly implemented in C.

Perhaps "properly implementable" might be more accurate. I would suggest
that C++ makes encapsulation and object access control easier than it is
in C.
That's ok, embedded platforms always have plenty of memory. :)


Who "abuses" embedded software, other than the implementor(s)?

The authors of software which accesses an API/interface to an embedded
system? I think what was intended is that it's easier in C++ than in C to
close off avenues of possible "abuse" - eg. by not exposing data/methods
that should not be accessed by the user of an interface to your system.

I'd prefer "more easily than can be achieved in C".
Not true. Perhaps you meant to write "I" instead of "you".

Possibly that too ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top