9 years, 1 month ago.

Why mbed selects C++?

Why mbed selects C++? In embedded field, C is a more widely-used language than C++. There are many firmware programmer don't know about C++(In China). If mbed used C, it would be welcomed by more programmer.

2 Answers

9 years, 1 month ago.

C++ is probably easier for beginners, and the overhead is acceptable for most of the mbed targets. While traditionally C is indeed more popular, I do think C++ is gaining ground. However it is possible to use much of the mbed API as C, since the underlying functions are all C. The C++ part is more a wrapper, but a wrapper which does implement some of the logic required.

That said, if you are competent in C, I don't think it should take you more than a week to get productive in C++, if you just look at the basic like classes. Of course you will run into stuff which takes more figuring out (like templates), but the basic is really similar.

Accepted Answer
9 years, 1 month ago.

You can write C code for the mbed compiler, just use .cpp extensions, not .c. Just remember to use,

  #ifdef __cplusplus
  extern "C" {
  #endif 	

  #ifdef  __cplusplus
  }
  #endif /*  __cplusplus */ 

Edit: Thanks Stephen!

Your code tags have spaces in them.

posted by Stephen Paulger 26 Mar 2015