prev up next   top/contents search

comp.lang.c FAQ list · Question 11.8

Q: I don't understand why I can't use const values in initializers and array dimensions, as in

	const int n = 5;
	int a[n];

A: The const qualifier really means ``read-only''; an object so qualified is a run-time object which cannot (normally) be assigned to. The value of a const-qualified object is therefore not a constant expression in the full sense of the term, and cannot be used for array dimensions, case labels, and the like. (C is unlike C++ in this regard.) When you need a true compile-time constant, use a preprocessor #define (or perhaps an enum).

References: ISO Sec. 6.4
H&S Secs. 7.11.2,7.11.3 pp. 226-7

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North