Re: C++ for Embedded Systems.
kanze skrev:
peter koch larsen wrote:
[concerning EC++...]
I believe I would recommend regular C++ in all but the
tightest environments.
I think most people would. I think that the alterative,
however, is more often C, and not regular C++. Whatever its
flaws, I suspect that EC++ has permitted a lot of applications
to use classes, etc., which otherwise would have been written in
C.
That might well be true. However embedded systems grow all the time,
and I know of systems with several megabytes of memory (e.g. mobile
phones). There it should be reasonable to use C++ which does not have
to use that much more memory than C (especially if you remove
iostreams).
[snip]
What I'm seeking guidance on is the usage of C++ / STL that
"optimizes for ram/rom size" rather than speed. Sort of like
-Os for STL usage guidelines.
The other common requirement in embedded systems is
determinancy. We need to know, even more than in desktop /
server apps, at design time the worst case behaviour. (Which
to me is an argument for using STL in embedded systems.)
However, a standard C++ gotcha is the time to process an
exception. A style guideline for embedded programmers should
probably highlight that in the appropriate context.
These are the sort of C++ vs Embedded gotchas and guidelines
I'm seeking.
This requires detailed study/analysis of the given compiler.
It depends on the level of detail you want. How to implement
exception handling is generally known, and it has a large cost
in code space. It's also generally accepted that raising an
exception and catching it are fairly expensive operations; if
you're writing a critical hard real-time function that has an
upper limit of 100us execution time, its something you don't
want to do.
Are you sure? 100 us is an awful lot of time today. I would not expect
an exception to take anything approaching one tenth of that unless
there is a huge stack depth. Assuming not to many rewinds (destructors
to run) I can't see a problem.
But there are (at least) two ways of handling exceptions (as you can
read in the performance report). They have different performance
metrics so far as I understand.
/Peter
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]