Skip to content

Instantly share code, notes, and snippets.

@Lifelovinglight
Last active May 6, 2017 08:14
Show Gist options
  • Save Lifelovinglight/db352afe00528e9be12f19c659ebf733 to your computer and use it in GitHub Desktop.
Save Lifelovinglight/db352afe00528e9be12f19c659ebf733 to your computer and use it in GitHub Desktop.
so confuse
struct struct_i_want_to_put_inna_list {
struct list_head nextelem;
int mydata;
};
struct list_head my_list;
INIT_LIST_HEAD(&my_list);
struct struct_i_want_to_put_inna_list *current_elem;
int sum_of_two_first_elements = 0;
current_elem = first_entry_or_null(my_list, struct struct_i_want_to_put_inna_list, nextelem);
sum_of_two_first_elements += current_elem->mydata;
current_elem = first_entry_or_null(current_elem->nextelem, struct struct_i_want_to_put_inna_list, nextelem);
sum_of_two_first_elements += current_elem->mydata;
//and now sum_of_two_first_elements contains the sum of the mydata fields in the two first cells of the linked list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment