Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Concatenated if and preprocessor Date: Fri, 14 Mar 2025 15:29:36 -0700 Organization: A noiseless patient Spider Lines: 40 Message-ID: <867c4rs0tr.fsf@linuxsc.com> References: <86frjfsgtb.fsf@linuxsc.com> <86bju3s5vp.fsf@linuxsc.com> <87zfhniaij.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 14 Mar 2025 23:29:37 +0100 (CET) Injection-Info: dont-email.me; posting-host="825d11fa9501a89399e86bed31f148c6"; logging-data="2273651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0DVPa64egBuWztxG/nohSATaVjIgymd4=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:X5Zbodiwi6cjMfnu/tL26rN+qN0= sha1:cuX8xb8hB8Y1l+U+3ZLM2lGTRVY= Richard Harnden writes: > On 14/03/2025 21:10, Keith Thompson wrote: > >> Tim Rentsch writes: >> >>> Richard Harnden writes: >>> >>>> On 14/03/2025 16:44, Tim Rentsch wrote: >>>> >>>>> for( int just_once = 1; just_once; just_once = 0 ){ >>>> >>>> Any reason not to say ... >>>> >>>> do { >>>> ... >>>> } while (0); >>>> >>>> ... ? >>> >>> In fact using do/while(0) is what I first wrote. But then >>> I thought, oh wait, what if an overzealous compiler gives >>> a warning because the while() expression is always false? :-/ > > That would break a lot of macros :) > >> [...] > > Hmm, clang with -Weverything is okay with: > do { ... } while (0); > > But not with: > if ( 0 ) { ... } > > But it's okay with: > if ( (0) ) { ... } These examples illustrate why I have the reaction I do. That plus the lack of clarity as to what the OP's actual requirements are explains my decision to use a for() rather than do/while(0).