Magic numbers are (almost) always bugs. And even when one uses a magic number as a magic number, one writes it in a macro or a variable that denotes that it is a magic number.

How can a compiler/preprocessor be configured to warn me if I'm using magic numbers?

EDIT:

The reason behind this question is that I see lots of code (here, from friends, from teachers even!) where magic numbers are used everywhere. Most of them (including teachers, sadly) don't know what static analysis tools are, but may know how to turn on compiler/preprocessor warnings, and would highly benefit from this feature.

0 Answers