I'm writing some code that would greatly benefit from the concise syntax of lambdas, which were introduced with C++ 11. Is this supported by the compiler?
How do I specify the compiler flags when compiling using Energia or embedXcode?
I'm writing some code that would greatly benefit from the concise syntax of lambdas, which were introduced with C++ 11. Is this supported by the compiler?
How do I specify the compiler flags when compiling using Energia or embedXcode?
On
As of February 2018, up to C++14 is supported with some limitations: http://processors.wiki.ti.com/index.php/C%2B%2B_Support_in_TI_Compilers
There isn't much about this topic on the TI site, or, at least, I don't know enough C++ to give you a detailed and precise response.
The implementation of the embedded ABI is described in this document that is mainly a derivation of the Itanium C++ ABI. It explains nothing about the implementation of lambdas nor the
auto, keyword (or probably I'm not able to derive this information from the documentation).Thus I decided to directly test in Energia. Apparently the
g++version is 4.6.3, thus it should support both.And in fact (from a compilation point of view, I don't have my MSP here to test the code) it can compile something like:
(the template works only if in an header, in the main sketch raises an error). To compile this sketch I had to modify one internal file of the editor. The maximum supported standard seems to be
-std=c++0x, and the compilation flags are in the file:in my setup the root is in
/opt/energia. Inside that file I modified line32(compiler.cpp.flags) and added the option. Notice that-std=c++11is not supported (raises an error).Unfortunately I have zero experience with embedXcode
:\Mimic
std::functionstd::functionis not provided, thus you have to write some sort of class that mimics it. Something like:may do the work, and it uses a simple trick:
As soon as you leave the capture empty, you are assured to have a "conversion" to a function pointer, thus you can store it without issues. The code I have written:
RETthat is the returned typeARGthat is one argument for the callback. In the majority of the case you may consider to usevoid*as common argument (cast a struct pointer in a void pointer and use it as argument, to counter-cast in the function, the operation costs nothing)NULL, while the second directly assigns the callback. Notice that the copy constructor is missing, you need to implement it.()) and to check if the callback actually exists.Again: this stuff compiles with no warnings, but I don't know if it works on the MSP430, since I cannot test it (it works on a common amd64 linux system).