C++11

Is Arduino C++11 compatible?

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.

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

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.)

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).

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:

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?

lardconcepts:
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).

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.

MichaelMeissner:
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?

MichaelMeissner:
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).

westfw:
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 "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?

the first thing I need to understand is classes, overloading etc

Which should be common to all versions of C++.

Arduino is not even C99, only C98?

You have to explicitly enable C99. The Arduino IDE doesn't.

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.

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.

If you are interested in a true object-oriented platform for Arduino you could take a look at Cosa: Cosa: An Object-Oriented Platform for Arduino programming - Libraries - Arduino Forum

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!

lardconcepts:
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.

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!