-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Enable C++11 and C11 #2175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable C++11 and C11 #2175
Conversation
I agree, I have been using It appears 4.8.1 has every feature of C++11 working except for garbage collection. https://gcc.gnu.org/gcc-4.8/cxx0x_status.html C++11 makes many things far easier, as you mentioned |
Hello, I might be wrong, but shouldn't you also update the platform.txt in the sam folder? Greetings |
6624d61
to
f308ebf
Compare
@Salandora, good point! I've rebased the changes and applied them to sam as well. Thanks for reminding me :-) Next up: Verify why some of the examples were changed (as in, the resulting .hex file changed) between with and without C++11. |
Ok, I finished compiling all the examples shipped with Arduino, with and without C++11. 55.5% of the compilations resulted in identical hex files. 38% of the compilations resulted in a (slightly) different hex file (for those keeping count, the remaining 6.5% were compilations that failed, with or without C++11). I had a closer look at the diffs for the builds that were different (I looked over them all, but not too close and every one of them, we're talking about 600 diffs here). I've seen the following differences:
Of course, there were some other changes like changed addresses etc, which resulted from the above changes. I haven't actually ran the examples for testing (too much!) but I've been running most of my sketches with C++11 enabled for more than a year now, so I'm pretty sure things will run as well. As far as I'm concerned, this PR is done and ready to be merged. |
@ArduinoBot build this please |
f308ebf
to
b85c0bf
Compare
I just rebased this against latest |
Can one of the admins verify this patch? |
@cmaglie, could you put this on the schedule for 1.6.1? Having C++11 support really opens up a lot of (optimization) opportunities, at little to know cost. It's a fairly trivial change, too. |
@ArduinoBot build this please |
This does not change anything, it just makes the defaults explicit.
This uses the gnu++11 standard, which is C++11 with GNU extensions. C++11 should be full compatible with the previously used C++98 standards, so all pre-existing sketches should continue to work.
Gcc 4.8 defines __cplusplus as 201103L, so we can check for that now. It still also defines __GXX_EXPERIMENTAL_CXX0X__, but this could help on other compilers, or if gcc ever decides to stop defining the experimental macro.
This uses the gnu11 standard, which is C11 with GNU extensions. Previously, gnu89 was being used, which is pretty ancient by now. C99 brings some important improvements, some of which were already available and used even without this option. C11 is more recent and brings more minor improvements. Most notable feature is the static_assert statement, allowing checking invariants at compiletime using the full C expressions.
b85c0bf
to
4abf6e4
Compare
I've just rebased this PR and re-ran the tests. Now, more examples compile to identical results than before, 82.6%. Not sure what changed there, though. A quick glance over the resulting assembly shows the same changes as described before. |
See https://www.google.com/fusiontables/data?docid=1tX3nZ7onuoBGuDoxDBbr7B0KRw-uKcbDTsEQfDlh#rows:id=1 for the build results. |
@ArduinoBot build this please |
On addition: Previously, this PR enabled C++11 and made the C99 default explicit. However, I've found out that the default for C is actually C89, so this PR actually changed the C standard used (which I think is a good thing). The latest version of this PR now also enables C11, the most recent version of the C standard (which, compared to C99, hasn't seen a lot of changes, just a few small additions of which |
I just found another reason for wanting C++11: delegating constructors, where a constructor can call other constructors in the same class. Is there anything blocking this? It's fairly trivial change, and more and more code seems to benefit from it. |
There are numerous reasons I can vouch for activating C++11. |
Rebased and merged. |
See arduino/Arduino#2175 Quoting the original commits from Matthijs Kooijman: Enable C++11 support This uses the gnu++11 standard, which is C++11 with GNU extensions. C++11 should be full compatible with the previously used C++98 standards, so all pre-existing sketches should continue to work. Enable C11 support This uses the gnu11 standard, which is C11 with GNU extensions. Previously, gnu89 was being used, which is pretty ancient by now. C99 brings some important improvements, some of which were already available and used even without this option. C11 is more recent and brings more minor improvements. Most notable feature is the static_assert statement, allowing checking invariants at compiletime using the full C expressions.
Now that we have a branch with a more recent gcc version we can enable
C++11 support.
This enables some more powerful and useful C++ features, like variadic
templates, rvalue refs / move constructors (for more efficient code -
String class already supports these), constexpr (to allow e.g. function
calls as constant values), foreach-style loop, enumeration classes,
static assertions. See http://en.wikipedia.org/wiki/C%2B%2B11 for
details.
These features are mostly useful for more advanced users and library
authors, but there is a lot in there that can make a significant
difference to code efficiency or conciseness.
Enabling C++11 should be completely backwards compatible.