I have a sketch that I have been working on for a month on my Linux development box. It works great and is functioning well on my device.
This morning I decided to make a few small adjustments so I checked the source out to my Macbook Pro (Snow Leopard).
When I attempted to compile the source I got the following compiler error on an array assignment:
RemoteStat.cpp: In function 'void setup()':
RemoteStat:107: error: expected primary-expression before '{' token
RemoteStat:107: error: expected `;' before '{' token
If I assign an array on the stack with an assignment I get the same error:
void foo()
{
int iNewArray[3] = { 0, 1, 2 };
}
So on the Mac, the AVR compiler will not allow me to do curly bracket array assignments within functions. This is valid C++ code, including the AVR compiler on Linux.
rabinnh:
So on the Mac, the AVR compiler will not allow me to do curly bracket array assignments within functions. This is valid C++ code, including the AVR compiler on Linux.
I don't agree that this is valid C++. However, I have never tried to put values into an array like that, so I did some experiments. I tried this with avr-gcc on OS X and got the same error. I then tried it with just gcc on both OS X and Linux. All three compilers agree, that syntax is invalid. (As does g++).
I think you got lucky it did something on one version of avr-gcc, but I don't agree this is valid.
(cmiyc): ~/> more test.c
#include <stdio.h>
int main ()
{
int iTest[3];
iTest = {0,1,2};
printf("%d\n", iTest[0]);
}
(cmiyc): ~/> gcc test.c -o test
test.c: In function ‘main’:
test.c:6: error: expected expression before ‘{’ token
(cmiyc): ~/> uname -a
Linux pavo 2.6.32.36-grsec #1 SMP Sun Apr 3 00:02:25 PDT 2011 x86_64 GNU/Linux
(cmiyc): ~/>