...
Code Block | ||
---|---|---|
| ||
float const pi = 3.14159f; float degrees; float radians; /* ... */ radians = degrees * pi / 180; |
Automated Detection
Compass/ROSE could detect violations of this rule by flagging any variable as a violation as long as:
- the variable is local to a function, or static (but not extern)
- It is never assigned to
- Its address is never evaluated.
These violations will be genuine, but ROSE can't catch all violations. In particular: - A variable whose address is taken might still be const
- Variables appearing in multiple files might still be const.
- Doesn't handle constant data on the heap
Risk Assessment
Failing to const
-qualify immutable objects can result in a constant being modified at runtime.
...