0

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

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 Mar 10 '17 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 Mar 10 '17 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.