Possible Duplicate:
“static const” vs “#define” in C
My first thought is that this is implied, but is there ever a reason why you would use const instead of #define?
If you set a global variable, why would you ever want to change it, and wouldn’t you want to protect it globally as well?
Const usually replaces
#define#defineis a pre-processor macro that can do textual replacement. You can use it to define a constant or a macro or do all sorts of other things.const is a type-safe way to define a compile-time constant
These two mechanisms occur at different times in the compilation process, but in general, const was created to rectify the problems of
#define.I’ve rarely seen people do something like
but it is legal.