This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

g++ 2.95 - const 2D array init bug?



  [The following problem may (or may not) be somehow related to
something
I posted on July 30 about 2D arrays of objects.]

  The problem appears to be something to do with making 2D arrays const.

  Using the following:

Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)

  with this code:
<---
#include <stdio.h>

const int func (int x) {
  printf ("%d\n",x);
  return x;
}

const int AR1[2] = { func(10), func(11) };

const int AR2[2][2] = { { func(0), func(1) }, { func (2), func (3) } };

int AR3[2][2] = { { func(20), func(21) } , { func (22), func (23) } };

int main ()
{
  printf ("Hello\n");

  for (int c = 0; c < 2; c++)
     for (int i = 0; i < 2; i++)
        printf ("AR2[%d][%d] = %d\n",c,i,AR2[c][i]);
}
--->

  compiled as

g++ -pedantic -Wall code.cc -o code

  we see no warnings, errors or indeed any messages of any sort.
When the code is run, we see:

10
11
20
21
22
23
Hello
AR2[0][0] = 0
AR2[0][1] = 0
AR2[1][0] = 0
AR2[1][1] = 0

  Thus it appears that the simple 2D int array and the 1D const int
array are
correctly initialized (i.e. the functions are called), however the 2D
const
int array is not similarly blessed.
  egcs 1.1.2 compiles this code OK and the resulting program does what
I'm
clearly expecting it to do.

  Thanks
    Ian.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]