All of lore.kernel.org
 help / color / mirror / Atom feed
From: vincent guffens <v.guffens@imperial.ac.uk>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: RE : a simple list
Date: Tue, 09 May 2006 22:29:44 +0100	[thread overview]
Message-ID: <446109C8.9010606@imperial.ac.uk> (raw)
In-Reply-To: <000b01c673a7$8e74cdb0$0b00a8c0@yoda>

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	other threads:[~2006-05-09 22:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-07 23:14 a simple list Guffens, Vincent
2006-05-08 23:51 ` RE : " Eric Salomé
2006-05-09  9:08   ` vincent guffens
2006-05-09 20:31 ` Eric Salomé
2006-05-09 21:29   ` vincent guffens [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=446109C8.9010606@imperial.ac.uk \
    --to=v.guffens@imperial.ac.uk \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.