pointer to pointer to pointer bug in cint

From: R. Eastman (eastman@tapestry.llnl.gov)
Date: Sat Jul 18 1998 - 09:41:53 MEST


Hi,

It seems that cint has a problem with pointers to pointers to pointers, i.e.

	double ***x;

In cint version 5.13.62 (which is what was in root version 1.03/09),
this apparently gets parsed as double** named *x, although the exact
behavior appears dependent on whether it is written as
	double*** x;
or
	double ***x;

After I discovered this I downloaded cint version 5.13.62 and compiled
it.  The more recent version seems to parse ***x correctly (which
means mine is not an original discovery), but it still doesn't behave
correctly. The following macro file demonstrates the problem:

//  - - - - - - - - - - - - - - -
// foo.C:
//  - - - - - - - - - - - - - - -
{
  double *x, **xp, ***xpp;
  x = (double*)malloc(8*sizeof(double));
  xp = (double**)malloc(4*sizeof(double*));
  xpp = (double***)malloc(2*sizeof(double**));

  for (int i = 0; i < 8; i++) x[i] = (double)i;
  for (int i = 0; i < 4; i++) xp[i] = &(x[2*i]);
  for (int i = 0; i < 2; i++) xpp[i] = &(xp[2*i]);
}
//  - - - - - - - - - - - - - - -

If you type
	.x foo.C
and then
	xpp[0][0][0]
you get
	0.0
which is correct. However
	xpp[0][0][1]
returns
	0.0
which is not correct (should be 1.0). Interestingly,
	*(*(*(xpp+i)+j)+k)
works, i.e. it gives the correct value of xpp[i][j][k].

Since the code I'm working on uses a struct data type with double*** member
to hold a 3-D array, I'm completely stuck.

cheers
Ron Eastman

 - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ronald G. Eastman
Lawrence Livermore National Laboratory
L-041
7000 East Avenue, PO Box 808, Livermore California 94551
001-925-423-7340
reastman@llnl.gov



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET