S
Szabolcs Nagy
is there a reason why const is not compile-time constant?
the usual example, where it'd be nice is array declaration:
const int N = 4;
float arr[N]
or one may want to use an enum for indices:
enum index {a,b,c,d,N};
float arr[N]
of course both are wrong and the solution is an ugly define
#define N 5
now i found another example where it would be nice to be able to
define compile-time constants:
const char * const a[] = {"a", "bb", "ccc"};
const char *b[] = {a[1], a[0], a[2], a[2]};
this is an error because a is not constant, which is a problem
since i don't know any elegant way to define b[] (let's say a and b
are globals in a one module c code)
(same problem with struct initialization)
any ideas?
the usual example, where it'd be nice is array declaration:
const int N = 4;
float arr[N]
or one may want to use an enum for indices:
enum index {a,b,c,d,N};
float arr[N]
of course both are wrong and the solution is an ugly define
#define N 5
now i found another example where it would be nice to be able to
define compile-time constants:
const char * const a[] = {"a", "bb", "ccc"};
const char *b[] = {a[1], a[0], a[2], a[2]};
this is an error because a is not constant, which is a problem
since i don't know any elegant way to define b[] (let's say a and b
are globals in a one module c code)
(same problem with struct initialization)
any ideas?