Any Open Source Embedded C++ Compiler ?

At the company where I work, its decided by higher authority that we will
use C since our software will run on some embedded platforms and for
embedded platforms C++ is not a good idea. Reading Stroustrup's FAQs
tells me the opposite: http://www.research.att.com/~bs/bs_faq.html

I am implementing a Priority-Queue (PQ) in C but I see C++ already has a
template, a generic PQ implemented in Std. Lib. Hence I am not much
interested in code-duplication, I am not interested in doing a work which
has already been done in a much better than I will ever do. We are using
gcc for our embedded platform, now I don't get it if gcc works on
embedded platform then why can't we use use g++ ? The embedded platforms
we are working on will mostly be *NIX or much less vxWorks and very
rarely something Windows based. (that's really not a ISO C++ question but
I asked it because I have to ask about templates on embedded platforms)

Has anyone worked on embedded platforms before, may be he can tell if we
can use templates over there and any other information will be
appreciated.

Advertisements

arnuld wrote:
> At the company where I work, its decided by higher authority that we will
> use C since our software will run on some embedded platforms and for
> embedded platforms C++ is not a good idea. Reading Stroustrup's FAQs
> tells me the opposite: http://www.research.att.com/~bs/bs_faq.html
>
> I am implementing a Priority-Queue (PQ) in C but I see C++ already has a
> template, a generic PQ implemented in Std. Lib. Hence I am not much
> interested in code-duplication, I am not interested in doing a work which
> has already been done in a much better than I will ever do. We are using
> gcc for our embedded platform, now I don't get it if gcc works on
> embedded platform then why can't we use use g++ ?

Policy rather than practicality!
> Has anyone worked on embedded platforms before, may be he can tell if we
> can use templates over there and any other information will be
> appreciated.

Advertisements

Guest

On Oct 6, 12:00 am, arnuld <> wrote:
> At the company where I work, its decided by higher authority that we will
> use C since our software will run on some embedded platforms and for
> embedded platforms C++ is not a good idea. Reading Stroustrup's FAQs
> tells me the opposite:http://www.research.att.com/~bs/bs_faq.html
>
> I am implementing a Priority-Queue (PQ) in C but I see C++ already has a
> template, a generic PQ implemented in Std. Lib. Hence I am not much
> interested in code-duplication, I am not interested in doing a work which
> has already been done in a much better than I will ever do. We are using
> gcc for our embedded platform, now I don't get it if gcc works on
> embedded platform then why can't we use use g++ ? The embedded platforms
> we are working on will mostly be *NIX or much less vxWorks and very
> rarely something Windows based. (that's really not a ISO C++ question but
> I asked it because I have to ask about templates on embedded platforms)
>
> Has anyone worked on embedded platforms before, may be he can tell if we
> can use templates over there and any other information will be
> appreciated.

You should really ask over in comp.arch.embedded. C++ can be used
successfully in embedded systems, particularly larger ones, but it's
often necessary to carefully control code size (many embedded systems
have very limited RAM and ROM, and things like template can lead to
major growth in code size), code speed (and things like extra this
pointers or vtable based calls can hurt a lot in some cases), and a
need to avoid things with unpredictable run-time impact, like dynamic
allocation (and since many C++ programs 'new' all over the place,
that's an issue). All that, plus poor or non-existent C++ support in
the tool chain, often leads embedded developers to stick with C.

But without knowing what you're doing, it's hard to say if C++ is
suitable.

> C++ can be used successfully in embedded systems,
> ...SNIP...
> But without knowing what you're doing, it's hard to say if C++ is
> suitable.

Well, the target embedded platform is not some specific one, it could
be anything with the guarantee that it mostly will be *NIX, very less
vxWorks and very rarely something Windows based. Thats all I can
guarantee. Currently the implementation of PQ is the only biggest
issue of using C. If I am able to use C++ then I will not be using any
OOP, only procedural style programming and Templates.

If I have not answered your question, please ask in detail and please
be specific.

arnuld wrote:
>> On Tue, 06 Oct 2009 18:18:52 +1300, Ian Collins wrote:
>
>> Policy rather than practicality!
>
> I prefer technical discussions over business ones and that's why I posted
> it here.
>
>
>> Often. About half of my C++ work is with embedded platforms.
>
> How much templates ? Currently using Templates is the only issue that is
> stopping me from recommending C++ instead of C.

I don't see what the big deal is with templates. There's plenty of
other language features that can be misused.

arnuld wrote:
>> On Tue, 06 Oct 2009 19:38:14 +1300, Ian Collins wrote:
>
>> I don't see what the big deal is with templates. There's plenty of
>> other language features that can be misused.
>
> I am not talking about misuse, I am talking about the possibility of
> using templates as efficiently as (hand-coded) C implementations (by an
> average guy) of them.

Ian Collins wrote:
> arnuld wrote:
>>> On Tue, 06 Oct 2009 19:38:14 +1300, Ian Collins wrote:
>>
>>> I don't see what the big deal is with templates. There's plenty of
>>> other language features that can be misused.
>>
>> I am not talking about misuse, I am talking about the possibility of
>> using templates as efficiently as (hand-coded) C implementations (by
>> an average guy) of them.
>
> Well if the alternative is macros, where's the problem?

Going back to your original question, using C++ will save the developers
form having to hand roll containers.

arnuld wrote:
> At the company where I work, its decided by higher authority that we will
> use C since our software will run on some embedded platforms and for
> embedded platforms C++ is not a good idea. Reading Stroustrup's FAQs
> tells me the opposite: http://www.research.att.com/~bs/bs_faq.html
>
> I am implementing a Priority-Queue (PQ) in C but I see C++ already has a
> template, a generic PQ implemented in Std. Lib. Hence I am not much
> interested in code-duplication, I am not interested in doing a work which
> has already been done in a much better than I will ever do. We are using
> gcc for our embedded platform, now I don't get it if gcc works on
> embedded platform then why can't we use use g++ ? The embedded platforms

search for cross-compiler g++ keywords
> we are working on will mostly be *NIX or much less vxWorks and very
> rarely something Windows based. (that's really not a ISO C++ question but
> I asked it because I have to ask about templates on embedded platforms)
>
> Has anyone worked on embedded platforms before, may be he can tell if we
> can use templates over there and any other information will be
> appreciated.
>

I am programming in c++ for a linux embedded platform. It is doable. Not
sure what else do you (or your superiors need).

Depending how powerful your embedded device is (CPU, memory, etc), you
might have to avoid RAII and some other nice c++ stuff

On Oct 6, 9:19 am, jacob navia <> wrote:
> arnuld a écrit :
>
>
>
> > At the company where I work, its decided by higher authority that we will
> > use C since our software will run on some embedded platforms and for
> > embedded platforms C++ is not a good idea. Reading Stroustrup's FAQs
> > tells me the opposite:http://www.research.att.com/~bs/bs_faq.html
>
> > I am implementing a Priority-Queue (PQ) in C but I see C++ already has a
> > template, a generic PQ implemented in Std. Lib. Hence I am not much
> > interested in code-duplication, I am not interested in doing a work which
> > has already been done in a much better than I will ever do. We are using
> > gcc for our embedded platform, now I don't get it if gcc works on
> > embedded platform then why can't we use use g++ ? The embedded platforms
> > we are working on will mostly be *NIX or much less vxWorks and very
> > rarely something Windows based. (that's really not a ISO C++ question but
> > I asked it because I have to ask about templates on embedded platforms)
>
> > Has anyone worked on embedded platforms before, may be he can tell if we
> > can use templates over there and any other information will be
> > appreciated.
>
> And why don't you use a priority queue in C? There are quite a few implementations!
>
> Look in
>
> http://www.google.com/codesearch
>
> and type
>
> priority queue. Choose plain C as language.

I've worked for a number of years with C++ on minimalistic, really
barebone embedded systems. Typically the requirement were that no
dynamic memory allocation was allowed,. hence most architectural
objects are created at startup. I've used plenty of template
programming to create signal-slot event publishing, priority queues,
binary trees, etc,. etc.

The downside is that templates will give you larger binary,. but it's
very cost effective since you don't have to reinvent the wheel every
time
+ with C++ and object orientation the speed of development and
maintenance will hopefully be less than if made with C

As a side point. At my latest project we used the following gcc (g++)
version
"powerpc-eabi-gcc (GCC) version 4.1.1 (Xilinx EDK 9.2)"

On 6 oct, 07:00, arnuld <> wrote:
> At the company where I work, its decided by higher authority that we will
> use C since our software will run on some embedded platforms and for
> embedded platforms C++ is not a good idea. Reading Stroustrup's FAQs
> tells me the opposite:http://www.research.att.com/~bs/bs_faq.html

Some ideas takes time to die.
> I am implementing a Priority-Queue (PQ) in C but I see C++ already has a
> template, a generic PQ implemented in Std. Lib. Hence I am not much
> interested in code-duplication, I am not interested in doing a work which
> has already been done in a much better than I will ever do. We are using
> gcc for our embedded platform, now I don't get it if gcc works on
> embedded platform then why can't we use use g++ ? The embedded platforms
> we are working on will mostly be *NIX or much less vxWorks and very
> rarely something Windows based. (that's really not a ISO C++ question but
> I asked it because I have to ask about templates on embedded platforms)
>
> Has anyone worked on embedded platforms before,

Plenty, mainly on ARM using ARMTools, IAR or g++.
> may be he can tell if we
> can use templates over there and any other information will be
> appreciated.

Yes, you can.

If you want some material, you could have a look at the MISRA C++
which is a norm for C++ in automotive industry.

arnuld wrote:
>> On Tue, 06 Oct 2009 20:12:03 +1300, Ian Collins wrote:
>
>> Going back to your original question, using C++ will save the developers
>> form having to hand roll containers.
>
> I just got a word from my seniors and was told of these:
>
> (1) A C compiler will definitely be available on the target embedded
> platform but a C++ compiler may or may not be available.
>

??? You debug your system with printf()s???
Why not unit test the code?
> (3) don't use malloc() unless it is absolutely necessary.
>

Don't use malloc() at all. Use new instead
> (4) The RAM available will be around 64-128 MB.
>

That is plenty.
> (5) The final executable should be less than 1 MB
>

Depends what it needs to do. You can easily get C executable to be
greater then 1 MB
>
> I don't think I have left with any choice here, except to use macros or
> void pointers to implement a PQ in C.
>
>

arnuld <> writes:
>> On Tue, 06 Oct 2009 20:12:03 +1300, Ian Collins wrote:
>
>> Going back to your original question, using C++ will save the developers
>> form having to hand roll containers.
>
> I just got a word from my seniors and was told of these:
>
> (1) A C compiler will definitely be available on the target embedded
> platform but a C++ compiler may or may not be available.
>
> (2) Use as much printf()s as you can for debugging purposes but code will
> be shipped with no printf()s.
>
> (3) don't use malloc() unless it is absolutely necessary.
>
> (4) The RAM available will be around 64-128 MB.
>
> (5) The final executable should be less than 1 MB
>
>
> I don't think I have left with any choice here, except to use macros or
> void pointers to implement a PQ in C.

Notice that with macros, you get the same code duplications as with
templates (for the small benefit of a theorically better type checking
by the C compiler, as oxymoronic that may sound).

I would advise you to use void* and a single copy of the PQ code.

If you are afraid of not being able to prove statically to yourself
that when you put objects of type T1 in a PQ, you get objects of type
T1 back, you could wrap all your objects in a structure with a type
tag to check dynamically that you've got objects of the right type:

With such a structure you can make a PQ of Object* instead of a PQ of
void*, and whatever the type of data you have, you can put it in a PQ,
and when you get it back with the typeTag field you can know what type
of value of really have.

See in the following program how the array o in main contains Objects
of any kind, (an int and a struct T1 for example), and how you can
process them in the loop.

On Oct 5, 10:00 pm, arnuld <> wrote:
> At the company where I work, its decided by higher authority that we will
> use C since our software will run on some embedded platforms and for
> embedded platforms C++ is not a good idea. Reading Stroustrup's FAQs
> tells me the opposite:http://www.research.att.com/~bs/bs_faq.html
>
> I am implementing a Priority-Queue (PQ) in C but I see C++ already has a
> template, a generic PQ implemented in Std. Lib. Hence I am not much
> interested in code-duplication, I am not interested in doing a work which
> has already been done in a much better than I will ever do. We are using
> gcc for our embedded platform, now I don't get it if gcc works on
> embedded platform then why can't we use use g++ ? The embedded platforms
> we are working on will mostly be *NIX or much less vxWorks and very
> rarely something Windows based. (that's really not a ISO C++ question but
> I asked it because I have to ask about templates on embedded platforms)
>
> Has anyone worked on embedded platforms before, may be he can tell if we
> can use templates over there and any other information will be
> appreciated.

Hi arnuld, long time, no see.

Just so you'll know, VxWorks bundles gcc and g++ with VxWorks.
I've used g++ on missile avionics with VxWorks.

On 7 oct, 18:11, Sherm Pendley <> wrote:
> arnuld <> writes:
> > At the company where I work, its decided by higher authority that we will
> > use C
> ...
> > We are using
> > gcc for our embedded platform, now I don't get it if gcc works on
> > embedded platform then why can't we use use g++ ?
>
> Because the boss said so.

If your superior is making a mistake or taking a decision for no valid
*technical* reason, the it is your responsibility to warn about it and
provide the relevant material.

In this case, the power that be have decided that C would be used
because "for
embedded platforms C++ is not a good idea"; it is not a well founded
opinion. It is true that C++ has still (IMHO) a lot of bad reputation
in the embedded world but it is well suited for embedded systems and
even desirable (for RAII by example).

For introducing C++ in the culture, a good first step is to say that
you could use a C++ compiler because it has stronger type safety but
continue to code in C (unless you use some C99 features). Then, start
to introduce practice that solve some of the less desirable aspect of
C (like scoped pointer to avoid leaks).

In article <>, ess says...
>
> At the company where I work, its decided by higher authority that we will
> use C since our software will run on some embedded platforms and for
> embedded platforms C++ is not a good idea. Reading Stroustrup's FAQs
> tells me the opposite: http://www.research.att.com/~bs/bs_faq.html
>
> I am implementing a Priority-Queue (PQ) in C but I see C++ already has a
> template, a generic PQ implemented in Std. Lib. Hence I am not much
> interested in code-duplication, I am not interested in doing a work which
> has already been done in a much better than I will ever do. We are using
> gcc for our embedded platform, now I don't get it if gcc works on
> embedded platform then why can't we use use g++ ? The embedded platforms
> we are working on will mostly be *NIX or much less vxWorks and very
> rarely something Windows based. (that's really not a ISO C++ question but
> I asked it because I have to ask about templates on embedded platforms)
>
> Has anyone worked on embedded platforms before, may be he can tell if we
> can use templates over there and any other information will be
> appreciated.

Not too long ago ARM advertized a job position in my area and asked for
C++ expertice. It actually turned out they do everything in C and Java
so the fact that I am a C++ "expert" was actually a detriment. I
actually got a big long dump about why C++ was inadiquate for embedded
development. Apparently what they really wanted was a Java developer
that could help write their optimizer.

The fears that perpetuate the assumption that C++ is "bad" on embedded
platforms are the same fears that perpetuate anti-template whackyness.
C++ templates and the standard library are "bloated" and "slow". This
is pure hyperbol but it doesn't really matter when you work at such a
place. In the end, using the standard library's queue is going to run
into the very brick wall that is stopping you from using the C++
language.

Where I work now *used* to be under a guy who had updated to C++ for the
OOP but was still stuck in the same nonsense world such anti-C++ people
are in. We were not allowed to use exceptions at all. Any use of the
standard library would result in a long, stupid argument with a total
moron. Luckily he ragequit when he got handslapped for being 4 hours
late to a meeting, but while he was here we were stuck in a world of
char* and homebrewed (and very broken) doubly linked lists.

In other words, even if you were in C++ I'd bet good money you'd be
stuck not using any of the main bullet points of doing so. Unless
you're willing to do battle against thick skulls filled with
misinformation...just bite the bullet and write it all in-house or
continue your search for a free C sollution.

On 06/10/09 07:52, arnuld wrote:
>> On Tue, 06 Oct 2009 19:38:14 +1300, Ian Collins wrote:
>
>> I don't see what the big deal is with templates. There's plenty of
>> other language features that can be misused.
>
> I am not talking about misuse, I am talking about the possibility of
> using templates as efficiently as (hand-coded) C implementations (by an
> average guy) of them.

It should be easy to get factual numbers and see whether there is much
code size overhead when using templates.

Write two applications that use a priority queue, one in C++ using
std:riority_queue<> and one in C using some C priority queue. Compile
say three versions of each application: one using a priority queue of
one element type, another using priority queues of ten different element
types and the third one using priority queues of a thousand different
element types. Compare the C and C++ executable sizes.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!