Re: Why ! C++
SasQ wrote:
Dnia Mon, 05 Mar 2007 08:15:19 +0100, Zara napisa??(a):
There are some systems written in C++. I am working on
an embeddded one that is comprised of a couple of
thousand lines of C++ plus a hundred lines of assembler,
plus 0 (zero) lines of C.
How did you make it?
I don't know, but I did it too. The smallest controller I used with C++ is
an 8 bit one with 1k of program memory and 64 bytes of data memory. Of
course there are some sacrifices you have to make on such a small system.
Most of the C++ standard library for instance wouldn't make much sense on
such a system, because it heavily depends on dynamic memory and the code
would be too big.
How can C++ work in an embedded system?
Just like C can.
I thaught C++ needs some additional implementation code,
which make base for C++ language facilities before it
call main() function.
So?
I mean the things like reserving static memory, calling constructors for
static objects, exception handling mechanisms etc. And I thaught that
new and delete operators have to be implemented using some system
API/kernel calls to some system memory manager, and cannot work in "blank"
environment without some system/kernel, which may do the memory management
for new/delete implementation code.
What makes you think new/delete must use a kernel to manage memory? It can
just as well have its own memory manager.
So how it's been done? I'm very curious about that, because the plain old
C doesn't need any runtime support AFAIK.
Well, it also has to initialize static variables. And if you have malloc and
free, implementing new and delete is trivial. Exception handling is
currently not supported by the implementation I use, but that's mostly
because nobody bothered to implement it yet. I guess on the small
controller I mentioned above, the overhead would be way too big, but there
are controllers of the same architecture with up to 256k of program memory
and (through an external memory interface) up to 64k of data space, and
this would definitely be enough for exception handling to be reasonable.