Due to project requirements I wanted to update mbed-os gnu version from gnu++98 to gnu++11, in order to use C++11 functionalities.
It has been recommended to use custom build profiles, but it doesn't apply to exporting, so it looks like there is no elegant way to enable C++11 for Eclipse currently.
@amq Profiles do apply to exportings, just not the GNU ARM Eclipse exporter. You could use the eclipse_gcc_arm exporter with a profile if you wanted. The --profile argument is accepted.
@amq Just for the record: Looking at the fix, this has nothing to do with C++11. The behavior of left shifting a negative value has never been defined by any C or C++ standards. From the beginning, even in C++ 98, the result of the expression (-1 << SOME_CONSTANT) was undefined (from the standard perspective).
EDIT: I figured out how to make an mbed::Callback out of a lambda, which makes most of what I said below incorrect.
auto myLambdaFunc = []{};
auto mbedCallback = callback(&myLambdaFunc, &decltype(myLambdaFunc)::operator());
EDIT (cont.): Still, moving to C++11 or higher would allow a simpler implementation of mbed::Callback, at least from the variadic templates.
~I found at least one reason to want to enable C++11 (or higher) not just in user projects, but also within Mbed OS itself: to replace mbed::Callback with std::function. mbed::Callback is apparently a kludge to work-around the lack of std::function. IME, it is not friendly to work with.~
~mbed::Callback is admittedly a stand-in for std::function, per the Mbed OS Platform documentation : "The Callback class should be familiar to users of the std::function class that C++11 introduced and is available for older versions of C++."~
~I have C++11 enabled in an Mbed OS-based project. Trying to create Callbacks from lambda functions is not fun. I've only been able to use one or two variable captures, due to the limited number of parameters accepted by mbed::Callback. (Presumably the lambda captures get translated to function parameters. I'm not sure where the extras come from.) I created a wrapper class in one case, just so I could attach a std::function to it.~
The template copy-pasta in mbed::Callback also impedes understanding from reading the code.
~I give props for the work-around, but I think it's had its day.~ What compilers and IDEs remain nowadays that don't support at least C++11, such that the Mbed team is still maintaining backward compatibility with older versions of C++? Can we please move on?
@bmcdonnell-ionx We would need to upgrade to Arm Compiler 6 and IAR EWARM 8. It's not so easy though: IAR EWARM 8 does not support C++03. This issue has more background on what an upgrade to C++11 would entail.
Actually, it looks like C++14 would be the standard when we upgrade.
@theotherjimmy, I knew I had seen a more comprehensive issue than this one! Thanks for the link.
Should this issue be closed, as it is superseded by #5507?
Yeah, please post in #5507
Hi there,
I am learning C++ right now for an embedded project. I notice the way one should code depends also on the C++ standard. As i see the online mbed compiler still compiles in C++98, which i find quite odd to say the least even as a beginner.
My question is: Is there a way i can change the setup of the online compiler to C+11 or C+14 standards?
If not can i just write my code locally in C++11 without using mbed-os (that seems to be outdated) and just upload a locally compiled bin to my board?
I don't believe you can change the online compiler, but if building locally, there is nothing stopping you from changing the language standard in tools/toolchains/toolchainname.py.
We are in the process of updating officially-supported toolchains and language standards, but we can only actively support and test one version of each, giving a total of 3 combinations at the minute - the compiler versions listed in the docs pages with the profiles the profiles you see in tools/toolchains.
I think you will have success with reasonable modifications to those profiles, including switching to C++11, C++14 or C11. I believe this will probably work most of the time on most platforms, but it is not properly tested and is unsupported.
@kjbracey-arm the c++/c standard is controlled by the build profile.
@idea--list, I've used a modified build profile to mbed compile a program with C++11.