A "double star" is a pointer to a pointer. Thus, NSError ** is a pointer to a pointer to an object of type NSError . This basically allows you to return an error object from a function. You can create a pointer to an NSError object in your function (name it *myError ), and then do something like this:
*error = myError;
to "return" this error to the caller.
In response to the comment below:
You cannot just use NSError * , because in C the parameters of the function are passed by value, i.e. the values ββare copied when the function is passed. To illustrate, consider this C code snippet:
void f(int x) { x = 4; } void g(void) { int y = 10; f(y); printf("%d\n", y);
Reassigning x to f() does not affect the value of the argument outside f() (for example, to g() ).
Similarly, when a pointer is passed to a function, its value is copied, and reassignment does not affect the value outside the function.
void f(int *x) { x = 10; } void g(void) { int y = 10; int *z = &y; printf("%p\n", z);
Of course, we know that we can change the value of the fact that z indicates quite easily:
void f(int *x) { *x = 20; } void g(void) { int y = 10; int *z = &y; printf("%d\n", y); // Will print "10" f(z); printf("%d\n", y); // Will print "20" }
So itβs reasonable that to change the value of what NSError * points to, we also need to pass a pointer to a pointer.
mipadi Mar 02 '09 at 21:42 2009-03-02 21:42
source share