Any Open Source Embedded C++ Compiler ?

A

arnuld

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.
 
I

Ian Collins

arnuld said:
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.

Often. About half of my C++ work is with embedded platforms.
 
R

robertwessel2

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.
 
A

arnuld

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.
 
A

arnuld

You should really ask over in comp.arch.embedded.  

Okay, I just posted it there.

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.
 
I

Ian Collins

arnuld said:
I prefer technical discussions over business ones and that's why I posted
it here.



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.
 
A

arnuld

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.
 
I

Ian Collins

arnuld said:
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?
 
I

Ian Collins

Ian said:
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.
 
J

jacob navia

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.
 
V

Vladimir Jovic

arnuld said:
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
 
K

KjellKod

arnuld a écrit :






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)"
 
M

Michael Doubez

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.
 
A

arnuld

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.
 
V

Vladimir Jovic

arnuld said:
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.

Read here how to create a c or c++ compiler for your target:
http://cross-lfs.org/view/clfs-sysroot/arm/cross-tools/chapter.html
(2) Use as much printf()s as you can for debugging purposes but code will
be shipped with no printf()s.

??? 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.

Jacob Navia posted a link how to do it in C ;)
 
P

Pascal J. Bourguignon

arnuld said:
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:

typedef struct {
int typeTag;
union {
int i;
float f;
double d;
char c;
String string;
T1 t1;
T2 t2;
...
} value;
} Object;

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.

------------------------------------------------------------------------
#include <assert.h>
#include <iso646.h>
#include <stdio.h>

typedef enum { false=0, true } bool;

typedef struct {
int allocated;
int length;
char* data;
} String;

typedef struct {
int i;
int j;
} T1;

typedef struct {
String name;
String email;
} T2;


enum {
type_nil=0,
type_int,
type_float,
type_double,
type_char,
type_String,
type_T1,
type_T2
};

const char* typeLabel(int type){
static const char* typeLabels[]={"null","int","float","double","char",
"String","T1","T2"};
return(typeLabels[type]);}

typedef struct {
int typeTag;
union {
int i;
float f;
double d;
char c;
String string;
T1 t1;
T2 t2;

} value;
} Object;


Object Nil={type_nil};


Object box_int(int i){
Object result;
result.typeTag=type_int;
result.value.i=i;
return result; }

Object make_t1(int i,int j){
Object result;
result.typeTag=type_T1;
result.value.t1.i=i;
result.value.t1.j=j;
return result; }


bool String_equal(String a,String b){
return((a.length==b.length)
and (0==strncmp(a.data,b.data,a.length))); }


bool T1_equal(Object a,Object b){
assert(type_T1==a.typeTag);
assert(type_T1==b.typeTag);
return((a.value.t1.i==b.value.t1.i)
and (a.value.t1.j==b.value.t1.j)); }

bool T2_equal(Object a,Object b){
assert(type_T2==a.typeTag);
assert(type_T2==b.typeTag);
return(String_equal(a.value.t2.name,b.value.t2.name)
and String_equal(a.value.t2.email,b.value.t2.email)); }


void doSomethingWithInt(Object o){
assert(type_int==o.typeTag);
printf("integer %d\n",o.value.i);
}

void doSomethingWithT1(Object o){
assert(type_T1==o.typeTag);
printf("T1 %d,%d\n",o.value.t1.i,o.value.t1.j);
}

bool equal(Object a,Object b){
if(a.typeTag!=b.typeTag){ return false; }
switch(a.typeTag){
case type_nil: return(true);
case type_int: return(a.value.i==b.value.i);
case type_char: return(a.value.c==b.value.c);
case type_float: return(a.value.f==b.value.f);
case type_double: return(a.value.d==b.value.d);
case type_String: return(String_equal(a.value.string,b.value.string));
case type_T1: return(T1_equal(a,b));
case type_T2: return(T2_equal(a,b));
default: return(false);
}
}

int main(){
Object o[]={box_int(42),make_t1(1,2),Nil};
int i;
for(i=0;not equal(o,Nil);i++){
switch(o.typeTag){
case type_int:
doSomethingWithInt(o);
break;
case type_T1:
doSomethingWithT1(o);
break;
default:
fprintf(stderr,"I cannot deal with objects of type %s"
,typeLabel(o.typeTag));
break;
}}
return(0);
}


/*
-*- mode: compilation; default-directory: "~/src/tests-c++/" -*-
Compilation started at Tue Oct 6 15:22:00

SRC="/home/pjb/src/tests-c++/tt.c" ; EXE="tt" ; gcc -g3 -ggdb3 -o ${EXE} ${SRC} && ./${EXE} && echo status = $?
integer 42
T1 1,2
status = 0

Compilation finished at Tue Oct 6 15:22:00
*/


------------------------------------------------------------------------

Oh, and if you grow tired of all the switches, you can put the
functions appliable on each kind of objects in a table, and have each
object keep a pointer to that table. Then you can write instead of:

switch(o.typeTag){
case type_int:
doSomethingWithInt(o);
break;
case type_T1:
doSomethingWithT1(o);
break;
default:
fprintf(stderr,"I cannot deal with objects of type %s"
,typeLabel(o.typeTag));
break;
}}

something like just:

call(o,"doSomething");


or even, with a macro such as:
#define S(O,M) call(O,#M)
just:

S(o,doSomething)
 
R

red floyd

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.
 
M

Michael Doubez

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).
 
N

Noah Roberts

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.
 
M

Maxim Yegorushkin

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::priority_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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top