On Tue, 17 Feb 2004, Sam Steingold wrote:
> 2. How do I interface to
> char **matGetDir(MATFile *mfp, int *num);
> What is the return value?
> Also, the documentation appears to indicate that what is actually
> returned is (char*[mxMAXNAM]), not (char**): why would they mention
This is not possible; a C function cannot return an array. :)
I suspect that your actual suspiction is that it might be
``char (*)[mxMAXNAM]''. In other words, the pointer to an array of
mxMAXNAM characters (or a pointer to the first element of an
array of arrays, whose elements are arrays of mxMAXNAM characters).
> mxCalloc() otherwise?
matGetDir returns a pointer to an internal array containing
pointers to the NULL-terminated names
so it's clear that it's ``char **'', just like the return type says.
They must do some funny allocation to allow you to blow this away with
just one call to their mxFree() function. The array of pointers and the
string data are all allocated in one memory block. Or perhaps the array
of pointers is dynamic, but the pointers are managed separately; maybe
the MATFile object owns these strings, and the dynamic array is just
used as a temporary object to retrieve the pointers in one call.
They probably use their mxCalloc() function like this:
char **arrayOfPointers = mxCalloc(numElements,
so the use of a calloc-like allocator does not support your
suspicion that it's not an array of pointers.