Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Marty
#46945 I need to pass different strings to a function. When I do so I get the compiler warning: "deprecated conversion from string constant to 'char*'".

The sketch loads to the ESP8266 and works just fine. If I run the same sketch on the Arduino Uno, I don't even get the warning.

Here is a very simple code example that produces the warning (actually twice):

Code: Select allvoid functionToPassTo(char* someString){
  //some code
}
void setup() {
  functionToPassTo("Hello");
  functionToPassTo("GoodBy");

}

It seems the proper way to do this is as follows:
Code: Select allvoid functionToPassTo(char* someString){
  //some code
}

void setup() {
  char passToFunction_1[] = "Hello";
  functionToPassTo(passToFunction_1);

  char passToFunction_2[] = "GoodBy";
  functionToPassTo(passToFunction_2);
}

That's a lot more code. If I use the "proper method" I would have to create about 30 variables to handle all my function calls.

Is there any hidden danger of using the code that produces the compiler warnings?

Thanks and regards
User avatar
By martinayotte
#46948 No, there is no danger at all.
But if you wish to unpollute the log, and since your function will never try to overwrite those strings, simply change your function as follow :

Code: Select allvoid functionToPassTo(const char* someString){
  //some code
}