Groups | Search | Server Info | Login | Register
Groups > comp.lang.c > #396565
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Loops (was Re: do { quit; } else { }) |
| Date | 2026-02-03 03:47 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <86ldhajbfx.fsf@linuxsc.com> (permalink) |
| References | (16 earlier) <H7yLP.2056536$OrR5.1414451@fx18.iad> <vtmgj8$g81k$1@dont-email.me> <vtn55a$17107$1@dont-email.me> <20250415201754.605@kylheku.com> <87h62o2296.fsf@nosuchdomain.example.com> |
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: [...] > I could write a macro like: > > #define ITERATE(var, from, to) for ((var) = (from); (var) < (to); (var)++) > > but then anyone reading the code has to understand both how C-style > for loops work and how the ITERATE macro works. Does the expansion > use < or <=? What happens if "to" is INT_MAX? Did the author of > the macro get everything right? An advantage of using a macro is that these questions need be answered only once, rather than at every place a for() loop would appear. > Now if someone else finds that such a macro makes things easier for > them, that's fine. But often, *in my opinion*, such macros make code > harder to read for someone who knows C well. Whether using a macro like ITERATE() makes code harder to read or easier to read is a testable proposition, and as such it deserves to be treated as a question of fact rather than as a matter of opinion.
Back to comp.lang.c | Previous | Next — Next in thread | Find similar
Re: Loops (was Re: do { quit; } else { }) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-02-03 03:47 -0800
Re: Loops (was Re: do { quit; } else { }) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-02-03 04:21 -0800
Re: Loops (was Re: do { quit; } else { }) Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> - 2026-02-04 23:40 +0000
Re: Loops (was Re: do { quit; } else { }) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-02-05 08:10 +0100
Re: Loops (was Re: do { quit; } else { }) Michael S <already5chosen@yahoo.com> - 2026-02-05 11:30 +0200
Re: Loops (was Re: do { quit; } else { }) Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-02-05 15:21 +0000
csiph-web