Pat wrote:
> What does it mean when a function argument contains multiple "*" - for
> example:
>
> /***************************************/
> int GetNameData(char*** faceName)
> {
> *faceNames = registeredFaceNames;
> return numOffaceNames;
> }
> /***************************************/
>
> or
>
> /***************************************/
> int AreValuesValid(char ** error, double * paramValues)
> {
> <statements>
> }
> /**************************************?
>
> ?
>
> I know a single "*" after a type designation makes it a
> "pointer-to-type", but what about multiple "*" (such as char*** or
> char ** shown above)? What do those do?
>
> Also, so far I've only seen this used with "char" types. Is this
> something specific to that type only?
>
> Thanks for any help.
A pointer to a pointer is usually used in C when when you want change the
original pointer itself. (In C++ you would probalby want to use a
reference
to a pointer).
Parameters in C and C++ are passed by value, they are copied. If you wish
to change the actual variable passed in you will need a pointer to it (or
a
reference).
This is what your first function GetNameData is doing, although it is
changing faceName to point to an array of pointers.
I.E.
char** Names;
( Names wants to point to an array of pointers).
int Count;
Count = GetNameData( &Names );
The variable Names is actually changed since a pointer (the address) of
Names was passed in.
This is not always the case for a ** though, an array of pointers is
sometimes set up this way, as we see for names. Since we want to change
names in the function an additional level of indirection is required, a
pointer to a char** or char***.
In C++ we would make the call
int GetNameData(char**& faceName)
Or a reference to a char**.
Now it's possible that we would want to pass our pointer to our array of
pointers to another function where it would be
DisplayNames( char** Names, int Count )
where we are not going to modify Names. But we still need a pointer to a
pointer because we still have an array of pointers.
--
Jim Langston
tazmaster@[EMAIL PROTECTED]


|