summaryrefslogtreecommitdiffstats
path: root/statistics.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-08-21 15:51:34 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-08-21 15:51:34 -0700
commit666538ec7739fe839623bd1b6f9f80ff884ad5a9 (patch)
tree6fede166e4de827b9d3d7b3baffa5272bbd16657 /statistics.c
parente46688d694d33f445ecb2368541898613af0f3b3 (diff)
downloadsubsurface-666538ec7739fe839623bd1b6f9f80ff884ad5a9.tar.gz
Add helper 'for_each_dive()' dive iterator
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>
Diffstat (limited to 'statistics.c')
-rw-r--r--statistics.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/statistics.c b/statistics.c
index 0a23f9022..b9d2c3b95 100644
--- a/statistics.c
+++ b/statistics.c
@@ -151,7 +151,7 @@ void process_selected_dives(void)
memset(&stats_selection, 0, sizeof(stats_selection));
nr = 0;
- for (i = 0; (dive = get_dive(i)) != NULL; ++i) {
+ for_each_dive(i, dive) {
if (dive->selected) {
process_dive(dive, &stats_selection);
nr++;