I understand having one asterisk * is a pointer, what does having two ** mean?
I stumble upon this from the documentation:
- (NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary **)errorInfo
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a pointer to a pointer, just like in C (which, despite its strange square-bracket syntax, Objective-C is based on):
and so on, ad infinitum (or until you run out of variable space).
It’s often used to pass a pointer to a function that must be able to change the pointer itself (such as re-allocating memory for a variable-sized object).
=====
Following your request for a sample that shows how to use it, here’s some code I wrote for another post which illustrates it. It’s an
appendStr()function which manages its own allocations (you still have to free the final version). Initially you set the string (char *) to NULL and the function itself will allocate space as needed.The code outputs the following. You can see how the pointer changes when the currently allocated memory runs out of space for the expanded string (at the comments):
In that case, you pass in
**strsince you need to be able to change the*strvalue.=====
Or the following, which does an unrolled bubble sort (oh, the shame!) on strings that aren’t in an array. It does this by directly exchanging the addresses of the strings.
which produces:
Never mind the implementation of sort, just notice that the variables are passed as
char **so that they can be swapped easily. Any real sort would probably be acting on a true array of data rather than individual variables but that’s not the point of the example.