Versions Compared

Key

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

...

In this noncompliant code, pi is declared as a float. Although pi is a mathematical constant, its value is not protected from accidental modification.

Code Block
bgColor#FFCCCC
langc
float pi = 3.14159f;
float degrees;
float radians;
/* ... */
radians = degrees * pi / 180;

...

In this compliant solution, pi is declared as a const-qualified object.

Code Block
bgColor#ccccff
langc
const float pi = 3.14159f;
float degrees;
float radians;
/* ... */
radians = degrees * pi / 180;

...