Deutsch   English   Français   Italiano  
<87zfnzpgmv.fsf@nosuchdomain.example.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: how to make a macro work as a single line if stmt without braces
Date: Sun, 22 Sep 2024 13:39:36 -0700
Organization: None to speak of
Lines: 40
Message-ID: <87zfnzpgmv.fsf@nosuchdomain.example.com>
References: <PaWdnZ3R-9zI6nP7nZ2dnZfqn_GdnZ2d@brightview.co.uk>
	<vcm16e$1hm2u$1@dont-email.me> <vcn6m8$1n1vu$1@dont-email.me>
	<vcp0rq$26p7b$1@dont-email.me> <20240922080605.59@kylheku.com>
	<vcpeo0$28shf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 22 Sep 2024 22:39:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="53afef797043d7014e444c472e5c9c8a";
	logging-data="2473026"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18aPoBONS9wI27lJI2/f6Xm"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:pqs1tqlPiKYaRnjJGxbS3JharY4=
	sha1:8Oeq4WVW9bMEhTcNSVb92Q4xcLk=
Bytes: 2755

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.com
void Void(void) { Void(); } /* The recursive call of the void */