Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson 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: <20240922080605.59@kylheku.com> 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 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 */