Prev: is this NP-Hard?
Next: An M/M/n queuing model simulation with Object Pascal and my Thread Pool Engine...
From: Juha Nieminen on 1 May 2010 06:15 In comp.lang.c++ Moi <root(a)invalid.address.org> wrote: > Personally I tend to use: > > for ( begin_expr; test_expr; next_expr) {;} > > , which immediately makes clear that the empty loop is intended. And causes a compiler warning due to a lone ';' if enough warning flags are used. What's wrong with {}?
From: Öö Tiib on 1 May 2010 07:23 On May 1, 12:49 pm, Phil Carmody <thefatphil_demun...(a)yahoo.co.uk> wrote: > James Kanze <james.ka...(a)gmail.com> writes: > > On Apr 25, 8:02 am, Juha Nieminen <nos...(a)thanks.invalid> wrote: > >> In comp.lang.c++ red floyd <no.spam.h...(a)its.invalid> wrote: > > >> > As a purely stylistic matter, my empty loops always look like: > > >> > for ( begin_expr; test_expr; next_expr) > >> > /* do nothing */ ; > > >> No, the proper way of writing an empty loop is: > > >> for(begin_expr; test_expr; next_expr) {} > > >> The empty block makes it explicitly clear that it's intended > >> to be empty, and not just a typo. (The empty block could also > >> be put in the next line, below the 'for', if so desired. A > >> matter of style.) > > > I'd argue that it's more than just a question of style. What > > the loop controls is on a line (or lines) after the loop, > > Bollocks. What the loop controls is the statement that follows > it. (Or in the case of a do-while, the statement between the do > and the while.) By the time the C parser is interpreting the > loop construct, there's no such thing as a 'line'. > > You're addressing _nothing_ but style, stop pretending otherwise. Correct. Style is anyway extremely important. For example if to read the posts in this group then some (like these of Kanze and Steinbach) are very easy to read thanks to good style, even on occasions when the information provided is incorrect or arguable. Style is even more important for writings written in C++ (source code), because C++ is never native tongue of writer. > However, thanks for making me peek into the documentation itself, > I've discovered a horribly misleading sentence in the standard, > so shall propose a correction. Which one?
From: Keith Thompson on 1 May 2010 13:03 Juha Nieminen <nospam(a)thanks.invalid> writes: > In comp.lang.c++ Moi <root(a)invalid.address.org> wrote: >> Personally I tend to use: >> >> for ( begin_expr; test_expr; next_expr) {;} >> >> , which immediately makes clear that the empty loop is intended. > > And causes a compiler warning due to a lone ';' if enough warning flags > are used. It does? A lone semicolon in this context is a null statement, which is perfectly legal. Compilers can certainly warn about anything they like, but I don't see why it would warn about this. > What's wrong with {}? Nothing that I can see. -- Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Gautier write-only on 1 May 2010 13:44 On Apr 25, 8:19 am, red floyd <no.spam.h...(a)its.invalid> wrote: > As a purely stylistic matter, my empty loops always look like: > > for ( begin_expr; test_expr; next_expr) > /* do nothing */ ; > > That is, I always explicitly comment the empty loop so that > it's clear that I wanted the loop to be empty. > > Makes life easier later on down the line. Funnily, a language's designers have thought to have the "do nothing" in the language, certainly for the same reason. E.g. for i in Some_range loop null; end loop; G.
From: Kenneth Brody on 1 May 2010 22:32 On 5/1/2010 1:03 PM, Keith Thompson wrote: > Juha Nieminen<nospam(a)thanks.invalid> writes: >> In comp.lang.c++ Moi<root(a)invalid.address.org> wrote: >>> Personally I tend to use: >>> >>> for ( begin_expr; test_expr; next_expr) {;} >>> >>> , which immediately makes clear that the empty loop is intended. >> >> And causes a compiler warning due to a lone ';' if enough warning flags >> are used. > > It does? A lone semicolon in this context is a null statement, which is > perfectly legal. Compilers can certainly warn about anything they like, > but I don't see why it would warn about this. [...] Consider: for ( begin_expr ; test_expr ; next_expr ); do_something(); The "lone semicolon" could easily be a typo, and not easy to spot at times. (Which is sort of what this sub-thread is all about.) -- Kenneth Brody
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: is this NP-Hard? Next: An M/M/n queuing model simulation with Object Pascal and my Thread Pool Engine... |