Re: Concatenated if and preprocessor

Liste des GroupesRevenir à cl c 
Sujet : Re: Concatenated if and preprocessor
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.c
Date : 14. Mar 2025, 23:57:39
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <8634ffrzj0.fsf@linuxsc.com>
References : 1 2 3 4 5 6
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
Richard Harnden <richard.nospam@gmail.invalid> 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? :-/
>
It's because of examples like this that I am wary of rules
like "enable all warnings" and "treat any warning condition
as an error."  I recently ran across a set of coding standard
rules that included these rules:  not just /some/ warning
conditions, but ALL warning conditions.  I still don't know
if they were literally serious.  (And my understanding is
clang has a -Weverything option, which enables all warning
conditions that clang is able to test for, no matter how
silly.)
>
I've worked under such coding standards.

I'm guessing this comment is an overstatement, and that you have
worked with similar but not nearly as stringent coding standards.
The coding standard I was referring to above says "Compile with
all possible warnings active" (and then also says something about
addressing them).

 Perhaps surprisingly, I
haven't found them to be terribly inconvenient.  I rarely ran into
a warning that was inordinately difficult to avoid.   I can see that
"clang -Weverything" would cause problems.

Yes, exactly my point.  "Lots of warnings" is not at all the same as
"all possible warnings".

The most common inconvenience was that if I experimentally commented
out some code, and it caused some variable not to be referenced,
the build would fail.  (I could just add `(void)foo;` to avoid that.)
To be clear, this was not code that I intended to commit.

Another question about coding standards is at what point in the
development process do they apply.  The rule in question here
says to _compile_ with all possible warnings active, presumably
meaning all compilations, not just those at checkin time.

I can imagine that there could be problems if a newer version of the
compiler produced new warnings, but we didn't often change compilers.

The two cardinal sins for giving error/warning options for a coding
standard are:  one, including an option whose meaning is not well
defined;  and two, including an option whose meaning changes over
time, either because of using a different compiler or because of
using a different version of the same compiler.  Saying it doesn't
happen often is no excuse;  developers should never agree to
requirements that mandate moving targets.

(In one obscure case, I wrote a wrapper script that could be
installed in $PATH as "gcc" that would invoke the real gcc and
filter out a particular warning.  The wrapper was necessary due to
the behavior of a build script, not to an explicit coding standard.)

A reasonable course of action under the circumstances, I expect.  At
the same time, it shows a shortcoming of the coding standard in
effect, if said standard says builds should not have any warnings
(and no exception is made for spurious warnings that occur because
of how builds are done).

Date Sujet#  Auteur
13 Mar 25 * Concatenated if and preprocessor26pozz
13 Mar 25 +- Re: Concatenated if and preprocessor1David Brown
13 Mar 25 +- Re: Concatenated if and preprocessor1James Kuyper
13 Mar 25 +- Re: Concatenated if and preprocessor1Kaz Kylheku
13 Mar 25 +- Re: Concatenated if and preprocessor1bart
13 Mar 25 +* Re: Concatenated if and preprocessor3Tim Rentsch
14 Mar 25 i`* Re: Concatenated if and preprocessor2Lynn McGuire
14 Mar 25 i `- Re: Concatenated if and preprocessor1Tim Rentsch
13 Mar 25 +- Re: Concatenated if and preprocessor1James Kuyper
14 Mar 25 `* Re: Concatenated if and preprocessor17pozz
14 Mar 25  +- Re: Concatenated if and preprocessor1David Brown
14 Mar 25  +- Re: Concatenated if and preprocessor1Dan Purgert
14 Mar 25  +* Re: Concatenated if and preprocessor12Tim Rentsch
14 Mar 25  i`* Re: Concatenated if and preprocessor11Richard Harnden
14 Mar 25  i +* Re: Concatenated if and preprocessor9Tim Rentsch
14 Mar 25  i i`* Re: Concatenated if and preprocessor8Keith Thompson
14 Mar 25  i i +* Re: Concatenated if and preprocessor3Richard Harnden
14 Mar 25  i i i`* Re: Concatenated if and preprocessor2Tim Rentsch
15 Mar 25  i i i `- Re: Concatenated if and preprocessor1David Brown
14 Mar 25  i i +* Re: Concatenated if and preprocessor3Tim Rentsch
15 Mar 25  i i i`* Re: Concatenated if and preprocessor2Keith Thompson
15 Mar 25  i i i `- Re: Concatenated if and preprocessor1Tim Rentsch
15 Mar 25  i i `- Re: Concatenated if and preprocessor1David Brown
15 Mar 25  i `- Re: Concatenated if and preprocessor1Lawrence D'Oliveiro
14 Mar 25  +- Re: Concatenated if and preprocessor1Keith Thompson
15 Mar 25  `- Re: Concatenated if and preprocessor1James Kuyper

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal