Re: Coding embedded systems with C
- From: "Hans" <hans_odeberg@xxxxxxxxx>
- Date: 29 Jul 2005 10:01:53 -0700
James wrote:
> I heard C is better for programming embedded systems than C++? Is this
> true, if so why?
That kind of depends on what you mean by "embedded".
Are you short on ROM/RAM - such as having to fit in to a 64kB address
space? Then some C++ features will be unavailable. You can probably
forget about RTTI, exceptions and STL. Dynamic memory will be a very
tight squeeze to fit in. Much of C++ will work, though. I built a
simple RTOS in C++ a while back; on a Renesas H8, the kernel and two
empty tasks weighed in at 5kB of code. Turning on exceptions swelled
the code to 300kB, due to the mass of library functions that were
linked in.
However, a cellphone with memory sizes in the 16MB range is still an
embedded system - and there all the above features can be included.
Do you have special realtime requirements, such as having to meet a
hard deadline? Many people will tell you to be wary of exceptions in
such circumstances, since the timing of stack unwinding can be hard to
predict - at least in the parts of your code that needs to meet those
deadlines; in my experience, only a very small part of the code in a
realtime system is subject to the realtime constraints.
Anyway, the bottom line is that C++ can be considered a superset of C.
For any given project, examine your constraints. Use the extra C++
features that fit within those constraints, be they memory or timing
related. Skip the C++ features that don't fit.
.
- Prev by Date: Re: printf
- Next by Date: Re: Copying a struct to a larger struct?
- Previous by thread: Re: Coding embedded systems with C
- Next by thread: Re: Big Endian
- Index(es):
Relevant Pages
|