c/2591: variable expression erroneously allowed to dimension array

allen.everhart@marcgs.com allen.everhart@marcgs.com
Thu Apr 19 14:26:00 GMT 2001


>Number:         2591
>Category:       c
>Synopsis:       variable expression erroneously allowed to dimension array
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 19 14:26:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Allen Everhart
>Release:        gcc version 2.8.1
>Organization:
>Environment:
AIX 4.2 also is accepted by CodeSorcery
/marces/gnu/lib/gcc-lib/powerpc-ibm-aix4.2.1.0/2.8.1/specs
>Description:
An automatic array is erroneously allowed to be dimensioned by a variable expression. This is an ansi violation and highly nonportable to other ansi compilers.
>How-To-Repeat:
gcc -Wall -ansi variabledimensionedarray.c
>Fix:
compile with xlc and fix syntax errors.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="variabledimensionedarray.txt"
Content-Disposition: inline; filename="variabledimensionedarray.txt"

int printf( char *, ... ) ;
int i=1 ;

int main()
{
        char buff[i] ; /* variable expression allowed to dimension array */ 

        buff[0] = 'f' ;
        buff[1] = 'o' ;
        buff[2] = 'o' ;
        buff[3] = '\0' ;
        return printf(  "%s %d\n", buff, sizeof(buff) ) ;
}



More information about the Gcc-prs mailing list