This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/7243: cannot declare an array at file level with constant expression for size
- From: jonathan dot ashley at praxis-cs dot co dot uk
- To: gcc-gnats at gcc dot gnu dot org
- Date: 9 Jul 2002 13:51:53 -0000
- Subject: c/7243: cannot declare an array at file level with constant expression for size
- Reply-to: jonathan dot ashley at praxis-cs dot co dot uk
>Number: 7243
>Category: c
>Synopsis: cannot declare an array at file level with constant expression for size
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Tue Jul 09 06:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Jon Ashley
>Release: 3.1.1 20020706 (prerelease)
>Organization:
>Environment:
Cygwin on Windows 2000. (Also reproduced on version 2.8.1 on Solaris.)
>Description:
If an array is declared at file level with a size given by a named constant (declared as 'const int x = 5' for example), the compiler incorrectly rejects it with the message "variable-size type declared outside of any function". This conflicts with A8.6.2 from K&R2.
>How-To-Repeat:
const int x = 1;
int y[x];
gcc -c demo.c
>Fix:
Don't do this.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="demo.c"
Content-Disposition: inline; filename="demo.c"
const int x = 1;
int y[x];