From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1FdaSM-0002fe-RU for mharc-grub-devel@gnu.org; Tue, 09 May 2006 18:13:26 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FdaSL-0002e5-C0 for grub-devel@gnu.org; Tue, 09 May 2006 18:13:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FdaSJ-0002c4-PS for grub-devel@gnu.org; Tue, 09 May 2006 18:13:25 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FdaSJ-0002bn-JP for grub-devel@gnu.org; Tue, 09 May 2006 18:13:23 -0400 Received: from [155.198.117.152] (helo=crumpet.cpn.ee.ic.ac.uk) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FdZnF-0003G9-0o for grub-devel@gnu.org; Tue, 09 May 2006 17:30:57 -0400 Received: from localhost ([127.0.0.1]) by crumpet.cpn.ee.ic.ac.uk with esmtp (Exim 4.44) id 1FdZm4-0005ki-DM for grub-devel@gnu.org; Tue, 09 May 2006 22:29:44 +0100 Message-ID: <446109C8.9010606@imperial.ac.uk> Date: Tue, 09 May 2006 22:29:44 +0100 From: vincent guffens User-Agent: Mozilla Thunderbird 1.0.8 (X11/20060502) X-Accept-Language: en-us, en MIME-Version: 1.0 To: The development of GRUB 2 References: <000b01c673a7$8e74cdb0$0b00a8c0@yoda> In-Reply-To: <000b01c673a7$8e74cdb0$0b00a8c0@yoda> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: RE : a simple list X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 May 2006 22:13:25 -0000 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.