Adafruit-GFX-Library icon indicating copy to clipboard operation
Adafruit-GFX-Library copied to clipboard

Add const specifier for strings

Open kinafu opened this issue 5 years ago • 1 comments

Without the const specifier methods would be able to modify immutable strings.

  • it fixes the compiler warning: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  • prevents illegal operations on the passed char* strings.

I did not test the changes. I assume that right now the change is just relevant for the compiler, because the code currently does not illegally modify the passed char *. (Although in the future it could come in handy to receive a compiler message upon violations.)

kinafu avatar Jun 09 '20 17:06 kinafu

String "literals" can be converted to char*, but callers who are calculating their button labels from something other than a simple "literal" currently have to work around the lack of const in these parameter types, with unnecessary casts that might hide other problems in their code. So this should help callers write safer code in practice, not just silence a warning.

BillyDonahue avatar Jun 09 '20 19:06 BillyDonahue