Talk About Network

Google





Programming > C - C++ Learning > Re: char** or c...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 4136 of 4400
Post > Topic >>

Re: char** or char*** in function arguments?

by Ulrich Eckhardt <doomster@[EMAIL PROTECTED] > May 3, 2008 at 07:21 PM

Pat wrote:
> What does it mean when a function argument contains multiple "*" - for
> example:
> 
> /***************************************/
> int GetNameData(char*** faceName)
> {
> *faceNames = registeredFaceNames;
> return numOffaceNames;
> }

There's nothing special when it's a function argument.

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

int i; // integer
int* pi; // pointer to integer
int** ppi; // pointer to pointer to integer
int*** pppi; // pointer to pointer to pointer to integer

If you want, you can introduce further levels of indirection, though it
tends to not make code more easy to read and understand.

> Also, so far I've only seen this used with "char" types.  Is this
> something specific to that type only?

No. The reason that you have only seen this is probably that only char is
almost always used as 'char*' or 'char const*' in order to express a
string. Now, if you want a pointer to a string, you suddenly have two
levels of indirection, i.e. 'char**'. In above function, you additionally
have a pointer to an array of strings, which adds another level of
indirection.

BTW: when I see above code, I think it could be rewritten for better
readability. I guess that the code doesn't only store names, but also
further data associated with the name. In the form above, it stores an
array with the names and further arrays to store the associated data.
Instead of that, I would rather define a structure that holds all relevant
data including the name and then store an array of that structure.

Further, for any type that holds an array size or an object size, I would
always use size_t. That's the type that 'sizeof' yields and also the type
that e.g. 'strlen()' returns. This gives your program more consistency and
avoids justified warnings by the compiler.

Uli
 




 4 Posts in Topic:
char** or char*** in function arguments?
Pat <pkelecy@[EMAIL PR  2008-05-03 12:26:02 
Re: char** or char*** in function arguments?
Ulrich Eckhardt <dooms  2008-05-03 19:21:02 
Re: char** or char*** in function arguments?
Pat <pkelecy@[EMAIL PR  2008-05-04 13:10:09 
Re: char** or char*** in function arguments?
"Jim Langston"   2008-05-04 15:06:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Fri Jan 9 5:33:05 PST 2009.