]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Add helper 'for_each_dive()' dive iterator
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 21 Aug 2012 22:51:34 +0000 (15:51 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 21 Aug 2012 22:51:34 +0000 (15:51 -0700)
It's an easy thing to do, but the for-loop ends up being pretty ugly, so
hide it behind the macro.

It would be even prettier with one of the (few) useful C99 features:
local for-loop variables.  However, gcc needs special command line
options, and other compilers may not do it at all. So instead of doing

   #define for_each_dive(_x) \
      for (int _i = 0; ((_x) = get_dive(_i)) != NULL; _i++)

we require that the user declare the index iterator too, and the use
syntax becomes

   for_each_dive(idx, dive) {
... use idx/dive here ...
   }

And hey, maybe somebody actually will want to use the index, so maybe
that's not all bad.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

No differences found