Replace Magic Number with Symbolic Constant
- You have a literal number with a particular meaning.
Create a constant, name it after the meaning, and replace the number with it.
... eax = 0x7fffffff; ...
⇓
const int MAXINT = 0x7fffffff; ... eax = MAXINT; ...
Motivation
When compiling, all the semantic information concerning enumeration values, pre-processor macro definitions, and constants is lost. So all the symbolic constants must be specified during decompilation.
Mechanics
- Create a new constant with the number, named after the meaning.
- Replace the number with the newly created constant.