From 666538ec7739fe839623bd1b6f9f80ff884ad5a9 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 21 Aug 2012 15:51:34 -0700 Subject: 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 --- info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'info.c') diff --git a/info.c b/info.c index 242e4b24d..8db606344 100644 --- a/info.c +++ b/info.c @@ -519,7 +519,7 @@ int edit_multi_dive_info(struct dive *single_dive) int i; struct dive *dive; - for (i = 0; (dive = get_dive(i)) != NULL; i++) { + for_each_dive(i, dive) { if (dive == master || !dive->selected) continue; /* copy all "info" fields */ -- cgit v1.2.3-70-g09d2