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

Hi,

i got this warning at

char* commands[] = {"90 AA 14", "90 94 2C", "90 94 0D",
                    "90 94 0E", "90 94 25", "90 94 26",
                    "90 94 10", "90 94 11"
                   };

This String array is from docu here: https://www.arduino.cc/en/Reference/String

Strange is that i have this warning at my tablet but not at my PC.
If i use const char* .... the warning is away.

Why this warning is not shown everywhere and why i need const?

thanks

This String array is from docu here: https://www.arduino.cc/en/Reference/String

So what? You do NOT have a String or String array.

Why this warning is not shown everywhere

Different versions of the IDE/tool chain? You have NOT supplied anywhere near enough details for a definitive answer.

and why i need const?

The function you are trying to pass that array to says that the argument is const. It means that the function won't change the data pointed to. The compiler expects you to

  1. pass it a const array, agreeing that the function won't change the data.
  2. lie to the function, telling it that the argument is so const, be using a cast.
  3. ignore the warning.

Pick one or more of the above.

PaulS:
Different versions of the IDE/tool chain? You have NOT supplied anywhere near enough details for a definitive answer.

Its the same Version installed at both computers, V 1.8.4
New intallations, nothing changed. New script only with this declaration.

The function you are trying to pass that array to says that the argument is const. It means that the function won't change the data pointed to. The compiler expects you to

No function, only the declaration shows this warning.
Of course i can ignore this but i want to understand it.

only the declaration shows this warning.

What type do you think "90 AA 14" is? If you said anything other than const char *, you'd be wrong.

You are trying to store a const char * in a char * array. Same choices outlined above. Make the array const char *, lie (using a cast), or ignore the warning.

Udo59:
Its the same Version installed at both computers, V 1.8.4
New intallations, nothing changed. New script only with this declaration.
No function, only the declaration shows this warning.
Of course i can ignore this but i want to understand it.

Check if you have different settings on the two computers at File > Preferences > Compiler warnings.

PaulS:
What type do you think "90 AA 14" is? If you said anything other than const char *, you'd be wrong.

You are trying to store a const char * in a char * array. Same choices outlined above. Make the array const char *, lie (using a cast), or ignore the warning.

OK, its a const char *. I'm new at this and just read the docu about string array. So it seems the docu is not correct.

pert:
Check if you have different settings on the two computers at File > Preferences > Compiler warnings.

That was the reason but warnings where already off. Changed something else(line numbers) and the warnings where really off.

Thanks.

PaulS:
What type do you think "90 AA 14" is? If you said anything other than const char *, you'd be wrong.

You are trying to store a const char * in a char * array. Same choices outlined above. Make the array const char *, lie (using a cast), or ignore the warning.

Thanks a lot

I don't know if you can do char* name[], personally I do only char name[]. Anyways warmungs are not so important, because they doesn't stop the compilation.
After pay attenton: String is an object (and it isn't very safety on Arduino), string is char array (look at the size of s)

Silente:
I don't know if you can do char* name[], personally I do only char name[].

char* name[] is an array of pointers, so yes, you can do that. How would you create a multideminsional array of c-strings?

Silente:
Anyways warmungs are not so important, because they doesn't stop the compilation.

They are extremely important; maybe not in this case but they tell you that your code might exhibit unexpected behaviour. It's up to the developer to determine what the effect will be.

Udo59:
OK, its a const char *. I'm new at this and just read the docu about string array. So it seems the docu is not correct.

Which docu? A link will be useful.

Sorry, for me a bidimensional (I have never done more) array of char is

char name [2][3]={"..","//","::"};
name [0][0]='€';

I have never used pointers, sorry

Udo59:
why i need const?

Because, the compiler is trying to prevent you from shooting yourself in the foot. It's telling you that if the definition is left as-is, your code could dereference the pointer and inadvertently change the value of the string literals.

In the unlikely event that you actually want to dynamically change your 'commands', you can do something like this:

char commands[8][9];
char *newCommand;

void setup() {
  strcpy(commands[0], "90 AA 14");
  strcpy(commands[1], "90 94 2C");
  strcpy(commands[2], "90 94 0D");
  strcpy(commands[3], "90 94 0E");
  strcpy(commands[4], "90 94 25");
  strcpy(commands[5], "90 94 26");
  strcpy(commands[6], "90 94 10");
  strcpy(commands[7], "90 94 10");

    // Change a "command":
  strncpy(commands[3], newCommand, 9);
  commands[3][8] = '\0';
}

void loop() {
}

Silente:
Anyways warmungs are not so important, because they doesn't stop the compilation.

Warnings ARE important because they point out code that may be a mistake, even though the code is not strictly illegal. I always keep my warning level turned to ALL because I'd like to be told that I have made a silly mistake rather than later trying to figure out why my sketch is not doing what I thought I told it to do.
Many times I compile a sketch that someone says is "not working right" and find that the warnings point right to where they made a mistake.