c++ - Why does the ternary operator const my strings? -


i writing code graphical lcd driven atmega328, using arduino build chain stino ide. have function formats , displays number label. function:

void displaynumber(float value, char* label) 

i realise both parameters consted, maintain compatibility other code, this.

if call function follows:

displaynumber(externaltemp, "max"); 

it works fine. understand string literals behave strangely in can't modified (undefined behaviour) not declared const char* char*.

if try using ternary operator pass argument function:

displaynumber(externaltemp, animate10s?"max":"min"); 

i compiler error:

invalid conversion 'const char*' 'char*'

why ternary operator consting string?

the compiler used avr-gcc/avr-g++ version 4.3.2, 1 bundled arduino beta 1.5.6-r2.

there (or until recently) deprecated conversion string literal char * (without const have), lets simple call work.

the ternary expression not string literal, conversion cannot applied it.

(your best solution make sure function parameter declared taking const char *.)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -