Originally Posted by
lilzz
is there a case for
test(&foo); ?
because I have seen int * x; some_function(&x) used in a program.
Yes, if you want to change the address that x points to from within some_function, but have that change be visible outside some_function. E.g.:
Code:
void alloc_something(struct something **x)
{
*x = malloc(sizeof(**x)); // allocate a struct something, store it's address in *x
}
struct something *other_alloc_something(void)
{
return malloc(sizeof(struct something)); // allocate a struct something, return it's address
}
int main(void)
{
struct something *x, *y;
alloc_something(&x); // allocates a struct something and puts the address in x
y = other_alloc_something(); // also allocates a struct something and puts the address in y
free(x);
free(y);
}
EDIT: I prefer the other_alloc_something style, but either way you get the same results. In the first method, you have to check if x is NULL before you can safely do *x.