I am writing a code for ARDUINO UNO in arduino 1.8.1 and the following error is coming How to remove it?
C:\Users\Mahe\Documents\Arduino\sketch_mar09b\sketch_mar09b.ino: In function 'void updateState(byte)':
C:\Users\Mahe\Documents\Arduino\sketch_mar09b\sketch_mar09b.ino:243:60: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
DisplayInfo("RFID Scanner", "Starting up", HIGH, HIGH);
1 Answer 1
I am writing a code for ARDUINO UNO in arduino 1.8.1 and the following error is coming How to remove it?
C:\Users\Mahe\Documents\Arduino\sketch_mar09b\sketch_mar09b.ino:243:60: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
DisplayInfo("RFID Scanner", "Starting up", HIGH, HIGH);
To give a detailed answer the full prototype for DisplayInfo() is needed. The issue is that the literal strings are const char*
and the function parameters are declared as char*
.
The correct way to fix this would be to update DisplayInfo() so that the parameter types are const char*
. The dirty fix is to cast the parameters in the call.
DisplayInfo((char*) "RFID Scanner", (char*) "Starting up", HIGH, HIGH);
But I would not recommend that.
Cheers!
-
The correct way is always the better and the header of DisplayInfo() should be changed to use const keyword in parameters. If code is third party, author/maintainer should be also informed to patch it. Good answer @mikael-patel :)caligari– caligari2017年03月10日 11:13:53 +00:00Commented Mar 10, 2017 at 11:13
-
An alternative is to declare some string constants and then pass the variable names into the function. i.e.
const char cRFIDScanner[] = "RFID Scanner"; const char cStarting[] = "Starting up"; DisplayInfo(cRFIDScanner, cStarting, HIGH, HIGH);
Code Gorilla– Code Gorilla2017年03月10日 12:57:56 +00:00Commented Mar 10, 2017 at 12:57