[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
iterator macros and requiring gcc >= 3.0 and -std=c9x
From: |
Marcus Brinkmann |
Subject: |
iterator macros and requiring gcc >= 3.0 and -std=c9x |
Date: |
Fri, 6 Sep 2002 01:04:30 +0200 |
User-agent: |
Mutt/1.4i |
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 address@hidden
Marcus Brinkmann The Hurd http://www.gnu.org/software/hurd/
address@hidden
http://www.marcus-brinkmann.de/
- iterator macros and requiring gcc >= 3.0 and -std=c9x,
Marcus Brinkmann <=