How do I use C++ 11 with 1.5.8 on OS X 10.10?

I think that I am being told that it should "just work". However, I'm getting "error: range-based 'for' loops are not allowed in C++98 mode". I tried to find out where that platform.txt file might be, but it's not on my system and I don't know where to create it, or if that's even the right thing to do.

Can you give some example code that would provoke that error. I'd really like to see it.

Any use of a range-based for loop triggers the error.

int numbers[]{1, 2};
for (int i : numbers);

Oh well. I don't miss it :slight_smile:

KenF:
Oh well. I don't miss it :slight_smile:

Me neither, but for those of them that want it :-

Merry Christmas,

Graham

So how does it work. Would this be valid?

char letters[]{"ABCDEFGHIJKMNOPQRSTUVWXYZ"};
for (int i : letters)
  Serial.println("No that's not it");

Serial.println("It must be xmas, there's noel");

Yeah sorry, I wrote that article before 1.5.8 came out, Ill update soon.

Anyway, if you follow the instruction for modifying the platform.txt file you will be in luck.

KenF has a working version of the loop. C++11 introduces the auto keyword, so you can use that too.

Or a reference if you need to write the array.

char arr[10];

for( auto i : arr ){
  Serial.print( i, HEX );
}

for( char &i : arr ){
  i = random( 0, 10 );
}

ghlawrence2000:
Me neither, but for those of them that want it :-

http://forum.arduino.cc/index.php?topic=281761.msg1980305#msg1980305

I don't understand how that is useful in addressing my topic; I obviously found that link already. It doesn't address OS X, and I'm using 1.5.8.

The copy needs to be amended. 1.5.8 does not have C++ 11 enabled. Here is the path for OS X: Contents\Java\hardware\arduino\avr\platform.txt.

However, the compiler seems useless at the moment; trying to use range-based for loops on global variables results in

error: 'begin' was not declared in this scope
error: 'end' was not declared in this scope

Do you feel like sharing an example of what we are missing? :wink:

Merry Christmas! :grinning:

Graham

Jessy_C:
I don't understand how that is useful in addressing my topic; I obviously found that link already. It doesn't address OS X, and I'm using 1.5.8.

The copy needs to be amended. 1.5.8 does not have C++ 11 enabled. Here is the path for OS X: Contents\Java\hardware\arduino\avr\platform.txt.

Thank you, I have updated the page and added the OS X path. I'm assuming the path for the Due would be as follows: Contents\Java\hardware\arduino\sam\platform.txt.

Anyway, the changes should work. Can you verify if the GCC version is 4.8.1 like the windows version.

One of the compiler tools has it in its name on my system:

D:\arduino-1.5.7\hardware\tools\avr\bin\avr-gcc-4.8.1.exe

Or using the command line --version

avr-gcc-4.8.1 (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.