On Thu, Aug 7, 2008 at 6:10 PM, solsTiCe d'Hiver <solstice.dhiver@gmail.com> wrote:
Or what do we do here? Double pointers start confusing me. i reach here the limit of my knowlegde of C too.
but why not : if(data) { data = NULL; }
if have found by trial and error that's the only thing that is not seg faulting
and void **data; data=NULL; is the same than void **data=NULL;
If you do that and then call list_remove like this : alpm_list_remove(..., data); Then it is the same than alpm_list_remove(...,NULL); So what is the point? In this case, the list_remove can't give us back a pointer to the removed node. We don't want data to be NULL, we want it to be a valid address, where the list_remove function will be able to store something. I already gave you the usual way to provide that, used everywhere in pacman/libalpm, which is to define void *data (a pointer), and then give &data (the address of that pointer) as a parameter. If you insist on using a void **data (a pointer to another pointer) and passing data as a parameter, then you need the data value to be a valid memory address. If you let it undefined, it has usually some random value. And when you try to use that value as an address, by using *data, then boom, segfault. That is when you need malloc. malloc will allocate some memory and return a pointer to that allocated memory. data is then a valid memory address and *data can be used. Here is a more fun explanation : http://cslibrary.stanford.edu/104/