grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RE : a simple list


From: vincent guffens
Subject: Re: RE : a simple list
Date: Tue, 09 May 2006 22:29:44 +0100
User-agent: Mozilla Thunderbird 1.0.8 (X11/20060502)

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.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]