Why use Embedded C++

From emboxit
Jump to: navigation, search



mbed Example

  • This code can be compiled by:
  • mbed online compiler
  • Keil compiler
  • In both cases registration to mbed needed


Arduino example




MSP430

Hi Prad,
I do all my MSP430 programming in C++ and CCSv4. It works very well if you consider an MCU environment.
I have not found any disadvantage of C++ compared to C other then the compiler force you to a more accurate and readable code. 
Not any addtional code is created nor additional  storage space is needed.
Following hints may help you:
- Do not create classes which use the heap. This means all functions and variables should be static. 
Create your own initialization routine (Maybe a static module with constructor could work. I never tried). 
You can reduce the heap memory to 0.
- Be aware that unlike IAR the CCS does not initialize static variables. Initialization in your own Init() function 
allows you to reset a module as often you want.
Advantages you get by using C++:
You can publish and protect functions and variables.
You can even protect interrupt routines(as protected or private function) from unwanted access outside. 
Within the interrupt function you have full access to all class variables.
You can created virtual dummy clases and implement code in derived classes.
and many other advantages on top.
Regards
Guenther