views:

340

answers:

6

Hello,

Is there significant problem, if I write the code for embedded linux system using C++ language programming ?.

Actually, I have intention to port some code to arm linux, with arm-uclibc compiler.

Thanks

A: 

Is there a significant problem?

  • It depends on how you program. If you comment liberally, and organize your code well, then no - you won't have problems.
  • It depends on the debugging capabilities of your development environment. If it is not easy to use, you will have problems tracking down bugs.

If I'm not mistaken, arm-uclibc is a C compiler?

George Edison
Mawg
Good comments don't lead to runtime bloat. Or am I misunderstanding your comment?
George Edison
@George, I think his point was that good comments will indicate why some unusual C++ code was used in place of idiomatic C++. For example, to prevent the newbie programmers from changing a status code to an exception, which would be reasonable to do on a desktop machine, but might not be the best choice on embedded systems.
Michael Aaron Safyan
Ah, okay. I get it.
George Edison
+2  A: 

See my questions http://stackoverflow.com/questions/2226252/embedded-c-to-use-stl-or-not

and http://stackoverflow.com/questions/2226227/embedded-c-to-use-exceptions-or-not

Mawg
What does this have to do with the question?
George Edison
@George, these are important questions about what subset of features to use with C++ on embedded systems. See my own response to this question.
Michael Aaron Safyan
+4  A: 

As I read your question, I was thinking about traditional embedded programming until I saw the Linux part. C++ can be used in embedded programming with caveats around hidden constructors, etc. If you're running Linux, I suspect that you don't need to worry about that stuff.

Richard Pennington
but it is `embedded` Linux, on an ARM processor, not a quad-core desktop. I think that that `embedded` part cannot be dismissed lightly. Mainly he is asking about resources, I guess. Time and memory. "Linux" is not a magic word that means that "don't need to worry about that stuff".
Mawg
Thanks for the downvote, but Linux represents more overhead, even on an ARM than traditional embedded programming on bare metal or less resource intensive operating systems. I use Linux on a desktop and on more resource limited systems, as well as other OSes: Nucleous, eCos, vxWorks, bare metal. Do you?
Richard Pennington
+3  A: 

Are you asking about plain C++ or embedded C++? As I understand it, embedded C++ is pretty much dead. You can program in C++, but, depending on your requirements, there may be some constructs that you will want to avoid using. For example, if you don't have much space, you may want to avoid templates as much as possible (or to explicitly instantiate templates) to keep your template instantiations to a minimum. You might also want to avoid exceptions or RTTI to reduce the amount of generated type information (to save space) and also to avoid having to deal with exception safety (to keep potential pitfalls to a minimum) as well as the high cost of exception propagation (to shorten the longest execution path, for real time systems). Virtual functions should be OK (they don't introduce that much overhead), but if you have very strict requirements, you may also need to limit your use of those. If you do use exceptions, you should also be sure that the compiler supports them (as many cross-compilers for embedded systems do not).

Michael Aaron Safyan
I think, this is a significant problem i worried.
deddihp
In an embedded world, it is definitely possible to program in C++ but you do have to be careful. If you are writing a program from scratch and you have a good embedded C++ compiler (*much* harder to find than a C compiler), then you should be able to get your program working. If you are trying to port an existing C++ program to an embedded system, expect to spend a lot of time modifying and re-writing parts of the code to fit the limitations of your system.
bta
A: 

Porting large software might be troublesome. I have experience programming 8-bit motorolla microcontroller with gcc c++, but in my case I started from scratch, so it was easier. There were few problems I encountered, like using destructors stopped program from executing, and not taking care of call-stack would cause it to overflow over other program variables...

So, my advice for writing c++ code on embedded device, is not to do many changes at once. When you program in small increments it's easier to spot when something stops working because of buggy compiler or hardware.

AareP
A: 

I think using Linux in an embedded system is more questionable that using C++. In the sense that it is a more significant decision rather than necessarily a bad idea.

Most of the concerns relating to C++ in embedded systems are to do with code size and performance; many of the concerns are based on myth or are far less significant that you might think, but even where they have some justification, they pale into insignificance compared with the overheads of running Linux and the unsuitability of the Linux kernel for hard real-time and low latency applications.

I regularly use C++ in embedded systems on OS-less and RTOS based systems. Use of Linux is justified where real-time deterministic behaviour is not required but the device, filesystem, and networking support provided is useful (although much of this is achievable in other ways), and your system is endowed with significant resources; but it would always be last on my list of choices for an embedded system OS if there were no compelling requirement.

If you choose to use uClinux on an ARM with no MMU (an ARM7 or Cortex-M3 for example), then you loose a significant compelling reason for using Linux in the first instance - MMU protected processes/kernel.

Clifford
Embedded systems can get awfully powerful, and there's a lot of Linux out there running on special-purpose devices.
David Thornley
@David: I don't think I suggested anything to the contrary. The main point was that you should have a sound reason for choosing Linux for an embedded system since that decision will have a far more significant impact than C++ vs C. A system can be 'powerful' (however vague the term) and not use a Desktop/Server derived OS - I hope so otherwise perhaps I've been missing something in 20 years of embedded systems development!
Clifford
@Clifford: What I was saying is that using Linux may be the obvious best choice, depending on what's being done and what's embedded in. I took your first sentence as suggesting that Linux is questionable in an embedded system.
David Thornley
@David: I merely intended to suggest that it was a more significant decision than teh language choice. Perhaps the term 'questionable' was somewhat derogatory, but probably reflects a personal bias from my experience with embedded systems and RTOS environments. It is entirely application dependent, in the applications areas I happen to work in seldom would Linux be the best choice, or even a practicable one.
Clifford