Topic: auto scoped dynamic arrays
Author: vaughan@sunspot.cad.mcc.com (Paul Vaughan)
Date: 25 Jan 92 03:21:41 GMT Raw View
Cfront 2.1 (well, at least the Sun CC version of it) does not accept
the following code:
extern "C" int strlen(const char*);
void foo(char* s) {
char buff[strlen(s) + 1]; //error: bad operator in constant expression
}
but g++ accepts it and works just fine. I'm not sure why cfront would
require the size of automatically scoped arrays to be a constant
expression. I also notice that gcc will accept it but cc won't. About
all I can find in the ARM is that array declarations are of the form
D[constant-expression]. Has this been changed? Is it an issue to the
standards committee? Is it an ANSI vs. K&R issue?
Paul Vaughan, MCC CAD Program | ARPA: vaughan@mcc.com | Phone: [512] 338-3639
Box 200195, Austin, TX 78720 | UUCP: ...!cs.utexas.edu!milano!cadillac!vaughan
----------------------------------------------------------------------------------
Author: jbuck@forney.berkeley.edu (Joe Buck)
Date: 27 Jan 92 20:22:00 GMT Raw View
In article <30434@cadillac.CAD.MCC.COM> vaughan@sunspot.cad.mcc.com (Paul Vaughan) writes:
>
>Cfront 2.1 (well, at least the Sun CC version of it) does not accept
>the following code:
>
>extern "C" int strlen(const char*);
>
>void foo(char* s) {
> char buff[strlen(s) + 1]; //error: bad operator in constant expression
>}
>
>but g++ accepts it and works just fine.
Variable-sized arrays of this type are an extension to the language
provided by gcc and are also available in g++. They are not part of
either ANSI C or K&R C or ARM C++. It's not portable and won't work
anywhere but in the Gnu compilers. The -ansi flag turns off this extension
in gcc, not sure how to turn it off in g++.
--
Joe Buck jbuck@ohm.berkeley.edu