Lack of compilers.
Those that are available are typically limited in features.
More embedded programmers know C than C++.
> Why C is
> preferred than C++ in embedded systems?.
I think that question contains a generalization which
makes any answer moot.
-Mike
I don't know of any. Any disadvantages are more likely the result of the
programming techniques used than the language itself. For instance, memory
allocation is easier in C++, so programmers might be more tempted to put
'new' in places where they would think twice about 'malloc' in C. Dynamic
memory allocation in embedded systems, except at startup, is usually asking
for trouble, because it is hard or impossible to prove that fragmentation
won't result in a memory allocation failure after months of continuous
running. Also, any memory leaks are fatal. Remember that C++ is largely a
superset of C, so you can always choose which C++-only features to use or
ignore, or you can ignore them all, but I suppose you should take into
account the relative likelihood of a given programmer to do something
dangerous in each language.
Another possibility is that the available compilers are not reliable enough.
>Why C is
> preferred than C++ in embedded systems?.
Maybe because of the availability or reliability of C++ compilers, or
possibly because of a misplaced perception that the language itself is not
suitable for embedded systems.
David
> What is the disadvantage with C++ in embedded systems?.
There are more good optimizing C compilers than C++ compilers
for embedded systems.
> Why C is preferred than C++ in embedded systems?.
Because more embedded systems programmers know C
better than they know C++.
This situation may change rapidly soon.
Take a look at
the Vector, Signal and Image Processing Library (VSIPL) home page:
Click on
High Performance Embedded Computing Software Initiative
It will take you to the HPEC-SI home page:
There are ANSI/ISO C and C++ language bindings for the VSIPL API.
The libraries are targeted mainly for
embedded Digital Signal Processors (DSPs).
Of course, this topic has been discussed to death
in the comp.arch.embedded newsgroup.
The main reasons I've encountered is that most embedded software
programmers don't know C++.
In one project I worked on, we agreed that new code would be (or could
be) developed in C++. If any old code need to work with new code, the
new code must provide a C language interface.
A more important issue with embedded programming is encapsulation and
module / source re-use. I don't consider inheriting of parent code
to a child as re-use. I'm talking about _different_ projects sharing
source code. But that is one of my pet peeves.
-- Thomas Matthews
This is all bullbyproduct. C++ requires *no* overhead compared to C.
It would be nice if people would not spread urban legends here. If you
look at the definition of C++ you will see that *if* make the *same*
program in C and C++ there is *no cause* for which the C++ program
should be any slower. Of course, if you make a more robust (exceptions,
dynamic buffers etc) or a more dynamic or a more configurable program
you wiull pay for that. Usually less than doing it in C - if the change
is big enough.
The problem is that some software developers mindsets do not follow the
Moore's law and many people prefer to program as if we are still
in the early 80s.
The following articles cover C and C++ performance:
http://www.eventhelix.com/RealtimeMantra/basics/ComparingCPPAndCPerformance.htm
http://www.eventhelix.com/RealtimeMantra/basics/ComparingCPPAndCPerformance2.htm
Sandeep
--
http://www.EventHelix.com
EventStudio - Generate Sequence Diagrams in PDF