HOW TO FIX ERROR "warning: deprecated conversion from string constant to 'char*'

Hello, I'm currently trying to get my lcd to work and I keep getting an error code, here is the full error if anyone could help I would appreciate it a lot.

thanks

Error:

C:\Users\MAIAOD~1\AppData\Local\Temp\arduino_modified_sketch_391580\UTFT_Textrotation_Demo.ino: In function 'void loop()':

C:\Users\MAIAOD~1\AppData\Local\Temp\arduino_modified_sketch_391580\UTFT_Textrotation_Demo.ino:38:39: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myGLCD.print("Text rotation", 0, 0);

^

C:\Users\MAIAOD~1\AppData\Local\Temp\arduino_modified_sketch_391580\UTFT_Textrotation_Demo.ino:40:39: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myGLCD.print("0 degrees", 0, 16, 0);

^

C:\Users\MAIAOD~1\AppData\Local\Temp\arduino_modified_sketch_391580\UTFT_Textrotation_Demo.ino:41:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myGLCD.print("90 degrees", 319, 0, 90);

^

C:\Users\MAIAOD~1\AppData\Local\Temp\arduino_modified_sketch_391580\UTFT_Textrotation_Demo.ino:42:46: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myGLCD.print("180 degrees", 319, 239, 180);

^

C:\Users\MAIAOD~1\AppData\Local\Temp\arduino_modified_sketch_391580\UTFT_Textrotation_Demo.ino:43:44: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myGLCD.print("270 degrees", 0, 239, 270);

^

C:\Users\MAIAOD~1\AppData\Local\Temp\arduino_modified_sketch_391580\UTFT_Textrotation_Demo.ino:47:35: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myGLCD.print("45", 90, 100, 45);

^

C:\Users\MAIAOD~1\AppData\Local\Temp\arduino_modified_sketch_391580\UTFT_Textrotation_Demo.ino:48:35: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myGLCD.print("90", 200, 50, 90);

^

C:\Users\MAIAOD~1\AppData\Local\Temp\arduino_modified_sketch_391580\UTFT_Textrotation_Demo.ino:49:38: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myGLCD.print("180", 300, 200, 180);

^

They are warnings and in this case you can ignore them.
But, you can make them go away by casting the strings like this:

myGLCD.print((const char *)"Text rotation", 0, 0);

and do the same with all the others.

Pete

On top of casting to const char as a solution You would probably save some memory if instead of

myGLCD.print([color=red]"180"[/color], 300, 200, 180);

you were to write

  myGLCD.print([color=blue]180[/color], 300, 200, 180);

Same with the others numbers. You could also define a global

const char degreeString[] = " degrees" and instead of doing
[tt]myGLCD.print("270 degrees", 0, 239, 270);

You could first print the number 270 and then the degreeString. This way you'll allocate only once in memory the string " degrees"

Easiest thing is to ignore them. In C it would be correct, though it is one of the few things deprecated in C++, though it still works correctly, no need to worry about it (it should not complain as there is no difference between a const char * and a char * and a char[] a string being any of such, it is a case of standards writers attempting to make the language look more sophisticated when it is not).

3D8192:
it is a case of standards writers attempting to make the language look more sophisticated when it is not).

ROFL!!

++

-jim lee

el_supremo:
They are warnings and in this case you can ignore them.
But, you can make them go away by casting the strings like this:

myGLCD.print((const char *)"Text rotation", 0, 0);

and do the same with all the others.

Have you tested that? A string constant already is const char *.

(It's the opposite the function expects a char * not a const)

That's what I am getting at. A string constant is already const char *. So casting it to that won't achieve anything. You might cast it to char * which is quite possibly a bad idea.

Oh rats. I got it the wrong way round.

Pete

"Some Literal"

In C the type of "Some Literal" is an array of char but in C++ it is constant array of char.

For backwards compatibility with C, C++ (still) allows assigning a string literal to a char* but it provides a warning about this conversion being deprecated.

as said here:

el_supremo:
They are warnings and in this case you can ignore them.