I am writing some code for a graphical LCD driven by an ATmega328, using the Arduino build chain with Stino as my IDE. I have a function which formats and displays a number with a label. This is the function:
void displayNumber(float value, char* label)
I realise that both parameters could be const
ed, but to maintain compatibility with some other code, they are like this.
If I call the function as follows:
displayNumber(externalTemp, "MAX");
It works fine. I understand string literals behave strangely in that they can't be modified (undefined behaviour) but they are not declared as const char*
but char*
.
If I try using the ternary operator to pass an argument to the function:
displayNumber(externalTemp, animate10s?"MAX":"MIN");
I get a compiler error:
invalid conversion from 'const char*' to 'char*'
Why is the ternary operator const
ing my string?
The compiler specifically used is avr-gcc/avr-g++ version 4.3.2, the one bundled with Arduino Beta 1.5.6-r2.