Hey,
I was wondering if I can write C++ code for the NRF9160:
- Does the NRF9160 DK support C++?
- Is SEGGER IDE compatible with it?
- Is it recommended to use C++ in it?
Thanks in advance!
Tal
Hey,
I was wondering if I can write C++ code for the NRF9160:
Thanks in advance!
Tal
- The DK is a board. You can program it with any language you want as long as there is a compiler supporting the Cortex-M33. C, C++, Python, etc...
- The Segger IDE does not properly supports C++. Although it uses GCC, it stripped out most C++ support of GCC.
- C++ or not is a matter of tastes. I use C++ mainly in any embedded project. There are a lot of advantage to it. You can use C++ without real object design as most people do. Arduino, mBed are all C++. C++ is not slower than C as many lead to believe. It is the same performance. Performance is directly related the coder himself.
C is a subset of C++. Sample compiler for both. Any well written C code are always and must be 100% compatible with C++. If not, it is considered bad coding.
Hi.
As Mojo says, you can use any language as long as the compiler supports the Cortex M33.
When it comes to using C++ with the nRF Connect SDK, that is not recommended.
The Zephyr Project does support C++ using CONFIG_CPLUSPLUS and CONFIG_LIB_CPLUSPLUS, although it is still experimental. The up-stream tracking issue is here: https://github.com/zephyrproject-rtos/zephyr/issues/18554
When it comes to NRF, NRFXLIB, and MCUBOOT, I am not sure how well they support C++.
The main.c file must have a .cpp suffix for the build system to recognize that it should use a CXX compiler. See zephyr\samples\cpp_synchronization\src\main.cpp for a working C++ sample.
However, I would recommend using C unless you have a very good reason for using C++. That way, it will be more tested, and we will be more able to help you if you encounter any problems.
Best regards,
Didrik