Alex Rivera | Logout

C vs C++ in embedded Linux

Asked 2011-02-28T19:37:59.337
16

I am developing an application for embedded Linux (ARM). It will execute 500 times/sec, therefore speed is important. I would prefer to use C++ but I am afraid it will be slower than C even if I avoid fancy features like virtual functions. Is there a reason to use C or it's just as fine to write in C++?

Edit
Report

2 Answers

2

You can use C++ but be extra careful.

For size, keep a close eye on your linker map file. You can find it including tons of stuff you don't need, just from an innocent-looking declaration.

For speed, profile or random-pause often. It's super easy to do more news and deletes than you really need, especially with container classes, and be really careful with things like iterators. Often they're doing you un-asked-for favors.

You can step through the code at the assembly-language level to make sure it's only doing what you actually need, which should be about the same as the C code.

answered 2011-02-28T20:19:58.947
1

I am using ARM9 board for hardware control and I am using both C and C++ Application in 500 Mhz board. It is up to you to use the language and how you implement your logic to implement the functionality. Because I have not found any problem running my Application over the day controlling the hardware.

While writting your program, carefully select your variable, check it against extra instruction/loop, initialization. also use Gcc optimization flag while compilation.

I have not any problem running my Qt Application and C program on 500 Mhz ARM 9 board.

answered 2013-02-20T08:45:31.310

Your Answer