There's a lot of macros and functions defined by the framework that supports your sketch. There are a lot of words you can't use for variables, not just the normal C reserved words.
Can you not use the time-honored "i" for your index?
My question is really, why does this not work on the Due when it works on the Uno.
I can easily change index to i, in fact I've already changed it to index1, as its not in code that I wrote and i is probably already used as well.
The name index can be declared as a local inside a function, so the use of the name index is not actually prohibited or reserved at all, it just doesn't compile when used as a global, and hence appears to be an issue with the IDE / compiler system for the Due.
rogerClark:
My question is really, why does this not work on the Due when it works on the Uno.
Because they are different processors. The relative difference between a Due and Uno is actually greater than the difference between a PC and a Mac.
If you really want to know, search through Arduino\hardware\arduino\sam\ on your hard drive and be amazed at the amount of stuff that makes your sketch work.
Yes, the ARM chip has CMSIS and libsam libraries from the manufacturers to support all
the many thousands of registers and functions of the chip. Think of the Due as 50 times more
complex than the Uno and you'll get an idea of the difference...
The bottom line here is that string.h in AVR-GCC does not define index() whereas string.h in the ARM-GCC package does define index().
index() is a "BSD compatibility" function.
Because Arduino.h includes string.h and other standard includes, (presumably to save the user doing so) it means the user has to avoid those standard definitions. There is no way for the user to undefine them.
But if string.h was removed from Arduino.h I guess a lot of sketches would no longer compile.
It seems that a discrepancy between AVR and ARM is unavoidable here.