Pointer-to a pointer-to a pointer-to a CELL, called cell. As for how this pointer is actually used in the code, it's difficult to say with certainty.

>> FLUX **x1_fluxes, *x2_fluxes, x3_fluxes;

x1_fluxes is a pointer-to a pointer to a FLUX, x2_fluxes is a pointer to a FLUX, and x3_fluxes is a FLUX. Again though, it's tough to tell you how these are used. You would have to ask a better question; show us more what's going on, where your problem might be.

03-04-2008

Elysia

Pointer to pointer is usually associated to assign a value to a pointer.
Like say, you pass in a pointer to a function which that functions needs to assign. So it needs a pointer to that pointer, becoming a pointer to pointer.

03-04-2008

waynex

Cheers, you explanation is excellent. I really wasn't sure what the *** actually did.

The code is quite big 500kb of source. I found it in the code at a later time used in memory allocation, I don't know does this help you understand further what is happening:

Note: The code is a numerical simulation, it's a 3d code, so cells just refers to the 3d cell in question on the grid. the flux is just the amount of heat or material etc. flowing through a face of a cell.

Yes, in this case, it's used for a dynamic 3D array.
First is allocates an array of pointer-to-pointers (**), and since it's calloc, it returns a pointer to the memory on the heap. That's one.
Next, for each of these pointers, it allocates another array of pointers (*) and stores them in the pointer to pointers (**). That's two.
And lastly, it allocates the actual space for the actual data and stores it in the pointers (*).

03-04-2008

matsp

Yes, that is fairly typical 3D memory allocations for dynamic dimensioning of arrays. Since C (and C++) essentially only supports arrays of "size known at compile time"[1, 2], the only way to work around that is to have the code itself allocate the memory for the content of the arrays.

[1] Yes, I know some compilers support various forms of "dynamic" arrays.
[2] The constraint on "size know at compile time" is so that the compiler can arrange for the memory "behind" the array to be correctly sized. Of course, if the compiler "doesn't know", then it won't be able to arrange for the right amount of memory. To do this at runtime would require similar code to be generated by the compiler - and the language architects decided not to support this type of functionality in the current standard of the language.

--
Mats

03-04-2008

waynex

Thank again for your fast reply, that explains it perfectly. Thanks a million for your help.