Pages: [1]   Go Down
Author Topic: C++11  (Read 2466 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is Arduino C++11 compatible?
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It was my understanding any every program that works under C++03 would work under C++11.

I enabled C++11 for my projects by modifying the arduino source a little to provide a --std=gnu++11 switch to the compiler.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, Quick response.
Thanks, í'll get cracking.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6367
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The version of g++ shipped with the windows and Mac versions of Arduino seems to be from 2008...  (it still accepts --std=gnu++11, though.)

Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 50
Posts: 1765
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want C++11, you really need a more modern GCC (and then edit the software that compiles the Arduino to enable C++11 support).  I believe you want GCC 4.7 (4.7.1 was just released).
Logged

Wales
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's become abundantly clear that to make much use of the extendible libraries (new-liquidcrystal for example), I'm going to have to learn C++.

Reading this thread right here from a year ago, and looking at the answer at StackOverflow which says:

Quote
Only gcc 4.7 and above (and therefore avr-gcc 4.7 and above) support C++11.

I'm using the current 1.5.4 beta build, and my question basically boils down to:

Should I jump right in and learn C++11? Can I assume that most of what I'd want to do (ie: not very complex) will be supported by the 1.5 series of the Arduino IDE? Or should I stick to learning older versions?
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 50
Posts: 1765
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Should I jump right in and learn C++11? Can I assume that most of what I'd want to do (ie: not very complex) will be supported by the 1.5 series of the Arduino IDE? Or should I stick to learning older versions?
Well the problem is, the compiler released with the Arduino 1.5.4 beta release is still the 4.3.2 compiler that they've stuck with for years.  So, unfortunately, you are stuck at C++98 (well you could populate your own system with the newer compiler, but you wouldn't be able to share your code with the majority of users).
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6367
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm going to have to learn C++.
   :
Should I jump right in and learn C++11?
I would expect that most of "beginner level" C++ would be common to C++11 AND older versions.
Logged

Wales
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well the problem is, the compiler released with the Arduino 1.5.4 beta release is still the 4.3.2 compiler that they've stuck with for years.  

Hmmm, I've read that elsewhere. Does anyone know the particular reason they're sticking to a compiler version over 5 years old rather than the released, stable and fully C++11  compatible 4.8 compiler?

So, unfortunately, you are stuck at C++98 (well you could populate your own system with the newer compiler, but you wouldn't be able to share your code with the majority of users).

I would expect that most of "beginner level" C++ would be common to C++11 AND older versions.

I didn't want to sound like I was getting ahead of myself, but I was trying to fix something from other (non-arduino) C examples, and I was getting errors like "
Code:
error: ‘for’ loop initial declaration used outside C99 mode
".

So, Arduino is not even C99, only C98?

Now, I can work around that one, but it got me looking around. Currently, my learning is from The C++ Programming Language: Third Edition by Bjarne Stoustrup which I found free on a University's free open course material download.

I'm only on the first chapter, but I actually quite like the writing style. Then I discovered a new, current C++11 edition. £35 though!!

I also read several people answering the question "should I learn C before C++" with a resounding "no, pointless, jump right into C++".

Without me dragging this off-topic into a book/learning recommendation thread, and bearing in mind that the first thing I need to understand is classes, overloading etc just so I can make my OLED work with that new-liquidcrystal library, where would YOU start as a C++ beginner?
« Last Edit: October 16, 2013, 04:37:10 am by lardconcepts » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6367
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the first thing I need to understand is classes, overloading etc
Which should be common to all versions of C++.

Quote
Arduino is not even C99, only C98?
You have to explicitly enable C99.  The Arduino IDE doesn't.

Quote
Does anyone know the particular reason they're sticking to a compiler version over 5 years old rather than the released, stable and fully C++11  compatible 4.8 compiler?
It's been discussed pretty extensively in other threads.  Basically, there isn't much proof that the newer compiler is "stable", or that it is fully X+11 compatible for AVR (don't forget, there's no C++ library, so anything that's dependent on runtime functions won't work.)  Especially since Atmel is only distributing 4.7.  And since 4.4, 4.5, and 4.6 had known catastrophic bugs in the Arduino environment.
Arduino users probably account for 80% or more of the avr-g++ usage; it doesn't get a lot of other exercise or testing.

https://github.com/arduino/Arduino/issues/1208
Logged

Wales
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I think I'm decided now: I'm going to press on with the third (1997) edition of the C++ book and stick to the 98 standard for the moment.

Thanks for all the input and interesting info.
Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 6
Posts: 372
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are interested in a true object-oriented platform for Arduino you could take a look at Cosa: http://forum.arduino.cc//index.php?topic=150299.0

Cosa has an adapter pattern for LCD device that makes adding an LCD really easy. If the LCD controller is HD44780 or compatible there is already a number of access adapters.

Cheers!
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 50
Posts: 1765
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So, Arduino is not even C99, only C98?

Note, I said C++-98, not C99.  While they share a lot of common things, and C++ is mostly a superset of C, they are different languages.  Arduino uses C++ for the IDE files, not C.

The C++ standard that avr-gcc supports is the 1998 C++ standard, though I believe it does not invoke the C++ compiler in strict standards compliance mode.

I haven't been keeping track of the C standards compliance with GCC since leaving the C standards process (I work on the GCC backend), but in C mode, I would expect the 4.3.2 compiler to support C90 fully, and a few things from C99.
Logged

Wales
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again, both of you, for putting me straight!

Cosa does look interesting and well documented, especially with its LCD driver. But I also know my limits - it might have to wait until I've got a slightly(!) better grasp of the C++ fundamentals!
Logged

Pages: [1]   Go Up
Jump to: