const in C is very different from const in C ++.
In C, this means that the object will not be modified through this identifier:
int a = 42; const int *b = &a; *b = 12; a = 12;
In addition, unlike C ++, const objects cannot be used, for example, in switch labels:
const int k = 0; switch (x) { case k: break; }
So ... it really depends on what you need.
Your options
#define : really const, but uses a preprocessorconst : not really constenum : limited to int
larger example
#define CONST 42 const int konst = 42; enum { fixed = 42 }; printf("%d %d %d\n", CONST, konst, fixed); &konst;
source share