TheMadHouse
Member
I'm observing a difference in compiler behaviour between Arduino and Teensy.
Consider this very simple code - A function that takes a char array as a parameter and, as part of the function, makes changes to individual elements of the array.
Compile as Arduino - Function sees "data" as a char* and allows modification.
Compile as Teensy - Function sees "data" as a const char* and does not allow modification (test call 2 fails).
Any idea why?
I understood Teensy used the Arduino compiler, so why the difference in behaviour?
I would have thought the Arduino compile was correct, and Teensy is wrong.
Jim
Consider this very simple code - A function that takes a char array as a parameter and, as part of the function, makes changes to individual elements of the array.
Code:
void testFunction(char* data)
{
// Do stuff
data[3]='X';
// Do stuff
}
// Test call 1
char data[] = { "TestData1" };
testFunction(data);
// Test call 2
testFunction((char*)"TestData2");
Compile as Arduino - Function sees "data" as a char* and allows modification.
Compile as Teensy - Function sees "data" as a const char* and does not allow modification (test call 2 fails).
Any idea why?
I understood Teensy used the Arduino compiler, so why the difference in behaviour?
I would have thought the Arduino compile was correct, and Teensy is wrong.
Jim