warning: deprecated conversion from string constant to 'char*' [SOLVED]

The code below gives a warning during compilation of

warning: deprecated conversion from string constant to 'char*'

Is there another way to do the same avoiding this complaint by the compiler?

LogSDCard("NTP Syncronization Success",0,26,0);



bool LogSDCard(char *logData, byte Start, byte Len, byte time)

{

...
...
}

Thanks :slight_smile:

bool LogSDCard(const char *logData, byte Start, byte Len, byte time)

gfvalvo:

bool LogSDCard(const char *logData, byte Start, byte Len, byte time)

ok.. but then how about this :

LogSDCard(ReplyBuffer,0,19,1);

Is there another way to do the same avoiding this complaint by the compiler?

Yes. You have a string constant. I'll be you can find it. You are passing that string constant (who's type is const char *) to a function that expects a char *.

  1. Make the string not const:
char whatToPrint[40];
strcpy(whatToPrint, "NTP Syncronization Success");

and print that:

LogSDCard(whatToPrint,0,26,0);
  1. Use a cast:
LogSDCard((char *)"NTP Syncronization Success",0,26,0);
  1. And this is best - Fix your function declaration:
bool LogSDCard(const char *logData, byte Start, byte Len, byte time)

but then how about this :

What about it? If you make the function argument const, what that means is that the function guarantees not to change the pointed to data.

PaulS:
What about it? If you make the function argument const, what that means is that the function guarantees not to change the pointed to data.

Thanks PaulS for a comprehensive solution!