c - implementing list insert first in generic List -


listresult listinsertfirst(list list, listelement element) {     null_arg(list, list_null_argument);     node first = elementcopy(list, element);     null_arg(first, list_out_of_memory);     if(!list->size){         list->iterator = first;         list->last = first;     }     first->next = list->first;     list->first = first;     list->size++;     return list_success; } 

this code list insert first give me error "segmentation fault" when run in eclipse indigo. i've tried erase line:

list->first = first; 

and didn't give me error.

the function elementcopy works perfectly: creates new node data element , set next null.

node elementcopy(list list, listelement e){     node tmp = malloc(sizeof(*tmp));     null_arg(tmp, null);     tmp->data = list->copyelement(e);     null_arg(tmp->data, null);     tmp->next = null;     return tmp; } 


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -