g++ 2.95 bug

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Tue Nov 30 23:39:00 GMT 1999


> I was playing around w/ g++ trying to initialize a "const array" (which
> does not seem to be possible....)  The code is not done (or even right),
> but this is what caused the error, so that's what I'm sending you.

Thanks for your bug report. The mainline compiler says

cfact.cc: In method `CFact::CFact ()':
cfact.cc:7: assignment of read-only location
cfact.cc:8: assignment of read-only location
cfact.cc:9: assignment of read-only location
cfact.cc:10: assignment of read-only location
cfact.cc:11: assignment of read-only location
cfact.cc:12: assignment of read-only location
cfact.cc: In function `double factln (unsigned int)':
cfact.cc:34: `m_cache' undeclared (first use this function)
cfact.cc:34: (Each undeclared identifier is reported only once
cfact.cc:34: for each function it appears in.)
cfact.cc:37: implicit declaration of function `int gammln (...)'

so it appears the bug has been fixed.

As for initializing the array: The trick is to keep a non-const
pointer to the same array:

CFact::CFact() {
  double *cof = new double[6];
  cof[0] =  76.18009173;
  cof[1] = -86.50532033;
  cof[2] =  24.01409822;
  cof[3] = -1.231739516;
  cof[4] =  0.120858003e-2;
  cof[5] = -0.536382e-5;
  m_cof = cof;
}

Hope this helps,
Martin



More information about the Gcc-bugs mailing list