Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Making code reverse compatible to fit this standard sometimes breaks functionality but this is a good recommendation to follow on new code. An example of a situation where implementing this would break prior code is if a string literal is assigned to a non-const pointer as in the following example
Before changing string literals to constant pointers

Code Block
bgColor#FFcccc
char* CMUfullname = "Carnegie Mellon";
...
//take user input to determine string variable "school"
if(strcmp(school,"CMU"))
{
    school=CMUfullname;
}

...

If one were to simply change the declaration of the string literal "CMUfullname" to const this would be the output

Code Block
bgColor#FFcccc
const char* CMUfullname = "Carnegie Mellon";
...
//take user input to determine string variable "school"
...
if(strcmp(school,"CMU")==0)
{
    school=CMUfullname;
}

...