On Mon, 22 Nov 2004 11:19:55 -0600, Gopi Sundaram <go*****@cs.sc. edu>
wrote in comp.lang.c:
I have the following code:
const int num_segments = 16;
int some_function(v oid)
{
int key[num_segments + 2];
...
}
My compiler barfs out the warning "ANSI C forbids variable-size array",
but lets it pass.
Does an expression using a const-variable count for the purposes of
"variable-size array"? I was under the impression that declaration is
legal ANSI C.
The declaration is legal in a compiler that conforms with the updated
1999 version of the C language standard, although such compilers are
rather few and far between, and the conformance of most of them is not
complete. The error message you cite seems to indicate that your
compiler does not conform to C99, or is not being invoked in a C99
conforming mode, but rather accepts this declaration as a non-standard
extension of its own.
Under C99 automatic arrays, those defined inside functions without use
of the 'static' keyword, can have variable sizes so long as the size
is greater than 0.
It is illegal under the original ANSI 1989 and ISO 1990 standards.
Prior to C99, and for arrays with static storage duration even under
C99, the size of an array must be specified as a compile-time constant
expression. The value of an object, even a const qualified object, is
not a compile-time constant expression under any version of C.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html