Eric Salomé wrote:
> Hi Vincent,
>
> I picked up your email from the archive as I didn't received it yet.
>
> As you see, it's very easy with a simple #define to create simple code
> for simple cases and yet be powerful for more complex cases :
> #define grub_iterate_list_brk(list, func, context, it) \
> {typeof(list) el = list; it = 0; \
> while (el) {if (func(context, el)) {it = el; break;} el=el->next; }}
>
> that you can call with
>
> grub_iterate_list_brk(grub_devices, compare, dev, it);
>
> with the simpliest compare function between two devices, and you get
> in-line functions nearly as simpler as the one you wrote.
>
> But let's try this :
>
> item * grub_iterate_list_brk (item * start,
> void * (*fct) (void * a, void * b), void * search) {
> while (start && fct(search, (void *) start)) start =
> start->next;
> return start ? start : (item *) fct(search, NULL);
> }
>
> that you can call with :
>
> it = (dev *) grub_iterate_list_brk((item *) grub_devices,
> devcompare, device);
Thank you very, this is definitely interesting although I don't like
these explicit castings in the code, especially not the one to (item *).
But at the end of the day I think this is overkilled and the while (dev)
seems more appropriate for simple tasks like the one I need.
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel