Sujet : Re: how to make a macro work as a single line if stmt without braces
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 22. Sep 2024, 21:39:36
Autres entêtes
Organisation : None to speak of
Message-ID : <87zfnzpgmv.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6
User-Agent : Gnus/5.13 (Gnus v5.13)
Bart <
bc@freeuk.com> writes:
On 22/09/2024 16:11, Kaz Kylheku wrote:
[...]
Also GCC has been able to diagnose misleading indentation for some
years now.
>
How many years was that out of the last 52? How exactly do you turn it
on? Since -Wall -Wpedantic -Wextra doesn't report it.
The -Wmisleading-indentation option was added to gcc on 2015-05-12,
and incorporated into -Wall 2015-12-10. gcc 6.1.0 has the option
and includes it in -Wall; gcc 5.3.0 does not. (Are you using a gcc
release that old?) It uses the -ftabstop= option (defaulting to 8)
to determine whether indentation lines up or not.
Inconsistent tabstops and mixing of spaces and tabs can certainly
cause problems.
It is a failure in the design of the language.
I wouldn't quite go that far, but I partly agree with you. Perl
requires braces on compound statements, and I've largely adopted
that style in my own C code. If C had required braces (requiring
a compound-statement in most contexts that currently require a
statement), certain errors would have been more difficult to make.
And you could still write one-line if statements in the cases
where they might be clearer:
if (cond1) { do_this(); }
if (cond2) { do_that(); }
if (cond3) { do_the_other(); }
However, there is zero chance that this will be changed in a future
version of C. It would break too much existing code. Which is
why we're discussing ways to write reliable code given the existing
language rules.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */