0

warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

char* password = "1234"; // change the password here, just pick any 3 numbers. 

Where to write the string?

I tried to search and found a code, but I don't know if it's correct to insert that code.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
NIKITA
  • 1
  • String literals are immutable. Use `const char* password` if you won't change the contents of the string. If you want to change the contents, use another way. (for example, allocating arrays like `char password[]` or using Arduino's `String`) – MikeCAT Mar 22 '23 at 15:00
  • 1
    What do you not understand there? *ISO C++ forbids converting a string **constant** to 'char*'* – 273K Mar 22 '23 at 15:00
  • _"Where to write the string?"_ - The `-Wwrite-strings` warning means that your declaration would allow someone to _write_ into the string literal `"1234"`. If it compiled, you would be able to also do `password[0] = 'A';` and thereby write into the string literal. It compiles in C for legacy reasons but it has undefined behavior even in C. – Ted Lyngmo Mar 22 '23 at 15:05

0 Answers0