In embedded programming, for example, #define GLOBAL_CONSTANT 42
is preferred to const int GLOBAL_CONSTANT = 42;
for the following reasons:
In C the const
qualifier does not define a constant but instead a read-only object:
#define A 42 // A is a constant
const int a = 42; // a is not constant
A const
object cannot be used where a real constant is required, for example:
static int bla1 = A; // OK, A is a constant
static int bla2 = a; // compile error, a is not a constant
Note that this is different in C++ where the const
really qualifies an object as a constant.