iterator macros and requiring gcc >= 3.0 and -std=c9x

Marcus Brinkmann <[email protected]>
Newsgroups gmane.os.hurd.devel.readers
Message-ID <[email protected]>
Hi,

I would like some iterator macros for the driver plugin code in the console
client.  I have written this so far:

#define driver_iterate(drv)                                             \
  for (mutex_lock (&driver_list_lock), drv = &driver_list[0];           \
       drv <= &driver_list[driver_list_len - 1];                        \
       drv++, (drv == &driver_list[driver_list_len - 1]                 \
               ? mutex_unlock (&driver_list_lock) : 0)

Which can be used like this:

   driver_t driver;
   driver_iterate (driver)
     {
       printf ("%s\n", driver->ops->name);
     }

Neal pointed out that C99 allows to define variables in statements, so the
following would work:

#define driver_iterate                                                    \
  for (mutex_lock (&driver_list_lock), driver_t driver = &driver_list[0]; \
       driver <= &driver_list[driver_list_len - 1];                       \
       driver++, (driver == &driver_list[driver_list_len - 1]             \
                  ? mutex_unlock (&driver_list_lock) : 0)

Which can be used like this:

   driver_iterate
     {
       printf ("%s\n", driver->ops->name);
     }

eliminating the need for a user-defined variable.  It's no big deal, but if
you prefer the second version, we need to use -std=c9x in our CFLAGS.  What
do you think?

Thanks,
Marcus

-- 
`Rhubarb is no Egyptian god.' GNU      http://www.gnu.org    [email protected]
Marcus Brinkmann              The Hurd http://www.gnu.org/software/hurd/
[email protected]
http://www.marcus-brinkmann.de/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.