I'm having a hard time grasping the concept of multiple levels of indirection, that is for example a char **. I understand that passing a pointer to some data to a function means that memory for that data doesn't have to be allocated on the stack, thereby reducing overhead (of course memory for the pointer has to be allocated to the stack, 'though). Another use as I understand (and see the benefits for) is that if a pointer to data is given to a function, that function does not have to return new, modified data - this is in contrast to PHP in which you generally do not pass arguments by reference but work with the return-value of the function.
However, my grasp ends around there.
What I'm having trouble understanding is why a function would want, say, struct addrinfo **res parameter. Surely for this function to work with res it will have to dereference it twice (to get to the struct pointed to). Whereas if it was just struct addrinfo *res it would only need one dereference, again getting to the struct.
I use the struct addrinfo **res because I am currently looking at networking with C. The function that brought me to ask this question is getaddrinfo() which has the signature:
Thanks for your help,
Mark.
However, my grasp ends around there.
What I'm having trouble understanding is why a function would want, say, struct addrinfo **res parameter. Surely for this function to work with res it will have to dereference it twice (to get to the struct pointed to). Whereas if it was just struct addrinfo *res it would only need one dereference, again getting to the struct.
I use the struct addrinfo **res because I am currently looking at networking with C. The function that brought me to ask this question is getaddrinfo() which has the signature:
Code:
int getaddrinfo(const char *node,
const char *service,
const struct addrinfo *hints,
struct addrinfo **res);
Mark.
Comment