2 months, 1 week ago.

Warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]

I get the above warnings when using Mbed-OS, although it compiles and works, I want to update my Oled driver to work correctly on OS.

Any suggestions?

Thank you

main

oled.drawText(0,2,(FONT8X12),"Trying AUTOCONNECT",oled.toRGB(0,255,255));

oled.h

void drawText(int  column, int row, int font_size, char *mytext, int color);

oled.cpp

void OLED32028P1T::drawText(int column, int row, int font_size, char *mytext, int color){
    s.putc(0x73);
    s.putc(column); // column
    s.putc(row); // row
    s.putc(font_size); // font size (0 = 5x7 font, 1 = 8x8 font, 2 = 8x12 font, 3 = 12x16)
    s.putc(color >> 8);      // MSB
    s.putc(color & 0xFF);    // LSB
    for (int i = 0;  i < strlen(mytext); i++) {
        s.putc(mytext[i]); // character to write
    }
    s.putc(0x00);   // string terminator (always 0x00)
    getResponse();
}
Comment on this question

1 Answer

2 months, 1 week ago.

In C++11, string literal is const char*. You can cast it to char* like this.

oled.drawText(0,2,(FONT8X12), (char*)"Trying AUTOCONNECT", oled.toRGB(0,255,255));

Thank you Kentaro, that's cleared those warnings.

posted by Paul Staron 14 Aug 2019