I\'m coming back to some C development after working in C++ for a while. I\'ve gotten it into my head that macros should be avoided when not necessary in favor of making the com
is it reasonable to prefer using enums for constants rather than #define's ?
If you like. Enums behave like integers.
But I would still prefer constants, instead of both enums and macros. Constants provide type-safety, and they can be of any type. Enums can be only integers, and macros do not respect type safety.
For example :
const int MY_CONSTANT = 7;
instead of
#define MY_CONSTANT 7
or
enum
{
MY_CONSTANT = 7
};
BTW My answer was related to C++. I am not sure if it applies to C.