[NSWI004] Getting a pointer to the item with a link.
Vojtech Horky
horky at d3s.mff.cuni.cz
Wed Sep 30 09:42:11 CEST 2020
Hello.
Dne 30. 09. 20 v 9:34 Georgii Ekserdzhian napsal(a):
> Good morning,
> I'm working on a %pL placeholder and I encountered some problems.
> So I get a pointer to a list. I turn it's pointer into a string, that's
> fine.
> Now I need to get pointers to the items in that list.
> I need to iterate them first.
> That is done either by list_foreach() or I can do it just by jumping
> pointers to links and getting a pointer to each item with list_item().
> Both list_foreach() and list_item() require a type of a payload and a
> name of a link variable.
> In test cases it's a paw_t, but I suppose we need to make this work on
> any structure.
> I'm not sure how to make this generic.
Your reasoning is completely correct.
For this special case, we expect that you will iterate through the
prev/next pointers manually because there is no way how to pass
information about the actual payload type into your printf.
For other cases, the list_foreach() is the right approach as you usually
know the payload type.
Cheers,
- VH
More information about the NSWI004
mailing list