c/1540: Strange effects whe defining 2-dimensional arrays
lampe@tu-harburg.de
lampe@tu-harburg.de
Wed Jan 3 05:56:00 GMT 2001
>Number: 1540
>Category: c
>Synopsis: Strange effects whe defining 2-dimensional arrays
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Jan 03 05:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Mattias Lampe
>Release: gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
Intel Celeron 500 MHz, SuSE Linux 6.4 (Kernel 2.2.14)
>Description:
When defining a 2-dimensional array, having an y-dimension
of 1 and the last element 0 (see code example), the first
element of a previously defined array is modified (set to 0).
The same code works correctly with Visual C++ under
Windows NT.
The problem does not exist
- if the y-dimension is larger than 1 or
- if the last element of the array is not 0.
>How-To-Repeat:
Sourcefile (test.c):
----------------------------------------
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j;
int array1[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
int array2[2][1]={{1},{0}};
for(i=0;i<4;i++)
for(j=0;j<4;j++)
printf("%i ",array1[i][j]);
return 0;
}
---------------------------------------
Compile with
gcc -Wall test.c -o test
and run.
Output:
0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
(should be 1 2 3 4 ...!)
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list