Friday, August 5, 2011

PC-Lint: enum for constants

When using enum for constants, you should leave the enum anonymous like this:
enum { C = 123 };
Otherwise you'll get warnings like 641 when assigning from enum to integer or comparing enum and integer. This would trigger the warnings:
enum Tag { C = 123 };
You still might experience warnings because Lint assumes enums to be signed, so assigment to an unsigned integer raises a Lint warning. Consider to use #define or const for defining constants instead. Then you can clearly indicate the type of the constant.

No comments:

Post a Comment