??? 07/12/12 02:48 Read: times |
#187908 - C++ "better than C" for embedded systems Responding to: ???'s previous message |
I went to a seminar recently where a speaker gave a pretty decent talk explaining why he felt that C++ was often better than C for smallish embedded systems. Some key points that I remember are:
1. C++ new() and delete() may generate more code than malloc() and free(), but that's becuase they do more. 2. Using heap for dynamic storage is a bad idea in an embedded system regardless of whether you are using C or C++. Using pooled memory is safe, and easier to implement in C++ than in C. 3. Exception handling can bloat your code. Most compilers are now very good at optimising the 'sunny day' execution path, but you still end up with more code to deal with a thrown exception. Throwing exceptions in an embedded system is problematic anyway, as there is rarely a clear way of recovering. It can however be useful during the test and verification phases. 4. Virtual methods add some code in C++, but if you need that sort of functionality you would have to write you own additional code in C anyway. 5. Run Time Type Information (RTTI) bloats code. Turn it off and add your own subset if you really need it. 6. Templates are very useful and powerful tools, but can generate a lot of code. This may be because you need the code, but it may be because you aren't using them appropriately. |
Topic | Author | Date |
Who the hell uses C++ in embedded systems... | 01/01/70 00:00 | |
So? | 01/01/70 00:00 | |
beware of (verbal) inflation. | 01/01/70 00:00 | |
Not as many as some would think. | 01/01/70 00:00 | |
2% don't know | 01/01/70 00:00 | |
Same same | 01/01/70 00:00 | |
Surveys | 01/01/70 00:00 | |
Me! | 01/01/70 00:00 | |
Using tools that only supports C? | 01/01/70 00:00 | |
Tools and MISRA | 01/01/70 00:00 | |
C++ "better than C" for embedded systems | 01/01/70 00:00 | |
as far as the '51 goes | 01/01/70 00:00 | |
As far as '51 goes - C++ is still viable | 01/01/70 00:00 | |
class vs source | 01/01/70 00:00 | |
I did say "smallish" | 01/01/70 00:00 | |
Overkill? | 01/01/70 00:00 |