RE:pointer to pointer to pointer bug in

Masaharu Goto (MXJ02154@nifty.ne.jp)
Sun, 19 Jul 1998 21:37:00 +0900


Ron,

>// - - - - - - - - - - - - - - -
>// 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
>
>. 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].

double ***x; bug is fixed but xpp[i][j][k] notation is not supported
for double*** unfortunately.
As you find out *(*(*(xpp+i)+j)+k) notation works.
It is not very simple to fix this problem in cint and I'm currently too
busy.

>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.

It sounds like you are in urgent need. Would it be possible to find a
workaround? For example,

1) Precompile class or function which handles xppp[i][j][k].
double get3Dvalue(double*** xpp,int i,int j,int k) {
return(xpp[i][j][k]);
}
2) If you run this code only interpreted, you can allocate dynamic array
simply by
double xpp[n][m][l];
This is an extention that cint provides to C++. This workaround can not
be used if xpp is data member of a class.
3) Use notation as follows.
*(*(*(xpp+i)+j)+k)
4) Create and precompile double*** class.
class doublePPP {
double *ppp;
public:
doublePPP(double*** x) { ppp=x; }
double& operator()(int i,int j,int k) { return(ppp[i][j][k]); }
};

I'm sorry for inconvenience. I believe you can find reasonable workaround.

Masaharu Goto