Deutsch   English   Français   Italiano  
<20240922080605.59@kylheku.com>

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

Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.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 15:11:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <20240922080605.59@kylheku.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>
Injection-Date: Sun, 22 Sep 2024 17:11:57 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="707ca171a1a6fc18e8cf13991e973ba2";
	logging-data="2373757"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/A4G157+lSvLfFcThF+uqzTFXyqyj0/uA="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:KlyObVtp8L8/1Qr7SRMSeytfIls=
Bytes: 2529

On 2024-09-22, David Brown <david.brown@hesbynett.no> wrote:
> I am not suggesting overuse of braces.  I am suggesting /good/ use of them.
>
><https://www.synopsys.com/blogs/software-security/understanding-apple-goto-fail-vulnerability-2.html>
>
> That's perhaps the most famous example of the havoc caused by omitting 
> useful braces.
>
> Consistency and clarity is important.  So is maintainability.  Suppose, 
> for example, you want to add a line "attempts++;" alongside the "ok++;" 
> line.  When the braces are there, the change is exactly that - add the 
> new line you want.  Without the original braces, you are now making 
> changes to the structural syntax of the code as well when you add in 
> original braces - or you are making a mistake in the code.

My super advanced text editor from the future isn't letting me do that:

  if (failed)
    WARN("failed because...");
  else
    ok++;
  attempts++; // automatic deindent

When I add a line after ok++, it deindents it to be at the same
indentation level as the if, before letting me type any content into it.

OK, I lied about the super advanced from the future. It's just Vim.

Also GCC has been able to diagnose misleading indentation for some
years now.

Between those two, there is nothing to worry about; just concentrate on
whether it looks prettier without the braces or with.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca