Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #388485

Re: how to make a macro work as a single line if stmt without braces

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 2024-09-21 21:33 -0700
Organization None to speak of
Message-ID <877cb4qpd3.fsf@nosuchdomain.example.com> (permalink)
References <PaWdnZ3R-9zI6nP7nZ2dnZfqn_GdnZ2d@brightview.co.uk> <vcm16e$1hm2u$1@dont-email.me> <vcn6m8$1n1vu$1@dont-email.me> <87frpsr7tf.fsf@nosuchdomain.example.com> <vco1ig$20c3r$1@dont-email.me>

Show all headers | View raw


Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
> On 09/21/24 2:54 PM, Keith Thompson wrote:
>> One reason to "overuse" braces is that you can easily add another
>> statement.  If you write:
>>      if (failed)
>>           WARN("failed because...");
>>      else
>>           ok++;
>> and later decide you need two statements in the else clause, you
>> then
>> need to add braces.  If they're already there, you don't.
>
> Adding braces in this situation is _incomparably_ easier than
> splitting an annoying single-line `if` statement into multiple lines,
> discovered during an interactive debugging session. Which is something
> you yourself described as "easy enough" below.

Perhaps I don't use interactive debuggers as much as other programmers
do, but I certainly haven't found it terribly difficult to temporarily
reformat code as needed (not that I've run into that particular issue
very often).  I'm likely to be modifying and rebuilding the software
anyway.

>> What you call "Egyptian" braces is the style used by the creators of the
>> language 
>
> Firstly, this is style. Being a "creator of the language" does not
> make one an authority on code formatting style.

True.

> Secondly, most people pick up "the style used by the creators of the
> language" from the code samples used in the 2nd edition of K&R
> book. And, as we know, "the creators of the language" went a little
> lazy here. The samples were considered of "low importance" and fell
> victim to the tightening publishing schedules in front of the looming
> "threat" of the upcoming ANSI standard. The code samples were never
> properly updated to match the style and spirit of modern C.

You seem to be asserting that K&R-style brace placement goes against
"the style and spirit of modern C".  In my opinion and experience, it
absolutely does not.

You prefer braces on their own lines.  I prefer to put opening braces at
the end of the line.  Neither of us is objectively right or wrong.

> This is BTW, the reason we have to deal with that pesky and atrocious
> manner to cast the result of `malloc` - another practice erroneously
> believed to be "the style used by the creators of the language".
> 
>> and in a *lot* of open source software.  Even if you don't like
>> the style, you'll need to deal with it.
>> I have my own fairly strong preferences about brace placement, but the
>> most important rule is to follow the conventions of the code I'm working
>> on.
>
> Certainly. It is not a good practice to force your own style onto
> someone else's code or an already existing code. Still, in most
> reasonably organized professional development environments personal
> preferences are normally welcomed with certain granularity. It is
> usually organized on "per translation unit" basis.

That's not my experience at all.  In some environments, there's a
project-wide written coding standard (which may or may not be strictly
followed).  In others, the style is (ideally) consistent at least across
each project or subproject.

I suppose I could deal with a project where each translation unit has
its own style, but thankfully I've never had to.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

how to make a macro work as a single line if stmt without braces Mark Summerfield <mark@qtrac.eu> - 2024-09-21 07:35 +0000
  Re: how to make a macro work as a single line if stmt without braces Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-21 08:10 +0000
  Re: how to make a macro work as a single line if stmt without braces David Brown <david.brown@hesbynett.no> - 2024-09-21 10:47 +0200
    Re: how to make a macro work as a single line if stmt without braces Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-09-21 12:27 -0700
      Re: how to make a macro work as a single line if stmt without braces Bart <bc@freeuk.com> - 2024-09-21 21:11 +0100
      Re: how to make a macro work as a single line if stmt without braces Opus <ifonly@youknew.org> - 2024-09-21 22:39 +0200
      Re: how to make a macro work as a single line if stmt without braces Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-21 14:54 -0700
        Re: how to make a macro work as a single line if stmt without braces Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-09-21 20:05 -0700
          Re: how to make a macro work as a single line if stmt without braces Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-21 21:33 -0700
          Re: how to make a macro work as a single line if stmt without braces David Brown <david.brown@hesbynett.no> - 2024-09-22 14:15 +0200
          Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-27 03:38 -0700
      Re: how to make a macro work as a single line if stmt without braces David Brown <david.brown@hesbynett.no> - 2024-09-22 13:59 +0200
        Re: how to make a macro work as a single line if stmt without braces Kaz Kylheku <643-408-1753@kylheku.com> - 2024-09-22 15:11 +0000
          Re: how to make a macro work as a single line if stmt without braces Bart <bc@freeuk.com> - 2024-09-22 16:56 +0100
            Re: how to make a macro work as a single line if stmt without braces Michael S <already5chosen@yahoo.com> - 2024-09-22 19:27 +0300
              Re: how to make a macro work as a single line if stmt without braces Bart <bc@freeuk.com> - 2024-09-22 17:47 +0100
              Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-24 07:36 -0700
                Re: how to make a macro work as a single line if stmt without braces Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-09-24 07:52 -0700
                Re: how to make a macro work as a single line if stmt without braces David Brown <david.brown@hesbynett.no> - 2024-09-24 17:24 +0200
                Re: how to make a macro work as a single line if stmt without braces Bart <bc@freeuk.com> - 2024-09-24 17:22 +0100
                Re: how to make a macro work as a single line if stmt without braces Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-24 12:28 -0700
                Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-27 01:43 -0700
                Re: how to make a macro work as a single line if stmt without braces Bart <bc@freeuk.com> - 2024-09-24 17:35 +0100
                Re: how to make a macro work as a single line if stmt without braces Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-24 12:30 -0700
                Re: how to make a macro work as a single line if stmt without braces Bart <bc@freeuk.com> - 2024-09-24 20:42 +0100
                Re: how to make a macro work as a single line if stmt without braces Kaz Kylheku <643-408-1753@kylheku.com> - 2024-09-24 19:59 +0000
                Re: how to make a macro work as a single line if stmt without braces Bart <bc@freeuk.com> - 2024-09-24 21:12 +0100
                Re: how to make a macro work as a single line if stmt without braces Kaz Kylheku <643-408-1753@kylheku.com> - 2024-09-24 22:36 +0000
            Re: how to make a macro work as a single line if stmt without braces Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-22 13:39 -0700
              Re: how to make a macro work as a single line if stmt without braces David Brown <david.brown@hesbynett.no> - 2024-09-23 08:16 +0200
                Re: how to make a macro work as a single line if stmt without braces Richard Harnden <richard.nospam@gmail.invalid> - 2024-09-23 08:06 +0100
                Re: how to make a macro work as a single line if stmt without braces David Brown <david.brown@hesbynett.no> - 2024-09-23 11:14 +0200
                Re: how to make a macro work as a single line if stmt without braces Richard Harnden <richard.nospam@gmail.invalid> - 2024-09-23 11:37 +0100
                Re: how to make a macro work as a single line if stmt without braces David Brown <david.brown@hesbynett.no> - 2024-09-23 14:22 +0200
          Modern text editor - 'bout time someone paid attention to keeping the thread title relevant!!! (Was: how to make a macro work as a single line if stmt without braces) gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-22 16:03 +0000
          Re: how to make a macro work as a single line if stmt without braces David Brown <david.brown@hesbynett.no> - 2024-09-22 18:03 +0200
      Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-28 05:02 -0700
        Re: how to make a macro work as a single line if stmt without braces Michael S <already5chosen@yahoo.com> - 2024-09-28 20:30 +0300
          Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-28 21:53 -0700
            Re: how to make a macro work as a single line if stmt without braces Michael S <already5chosen@yahoo.com> - 2024-09-29 12:48 +0300
              Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-29 19:18 -0700
              Re: how to make a macro work as a single line if stmt without braces Alan Mackenzie <acm@muc.de> - 2024-09-30 15:05 +0000
        Re: how to make a macro work as a single line if stmt without braces Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-09-28 21:02 -0700
          Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-28 22:47 -0700
            Re: how to make a macro work as a single line if stmt without braces Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-09-29 07:41 -0700
              Re: how to make a macro work as a single line if stmt without braces Michael S <already5chosen@yahoo.com> - 2024-09-29 18:04 +0300
              Re: how to make a macro work as a single line if stmt without braces scott@slp53.sl.home (Scott Lurndal) - 2024-09-29 18:30 +0000
              Re: how to make a macro work as a single line if stmt without braces Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-29 16:39 -0700
                Re: how to make a macro work as a single line if stmt without braces Kaz Kylheku <643-408-1753@kylheku.com> - 2024-09-30 02:29 +0000
                Re: how to make a macro work as a single line if stmt without braces Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-30 11:26 +0200
              Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-29 18:39 -0700
              Re: how to make a macro work as a single line if stmt without braces Kaz Kylheku <643-408-1753@kylheku.com> - 2024-09-30 02:03 +0000
              Re: how to make a macro work as a single line if stmt without braces David Brown <david.brown@hesbynett.no> - 2024-09-30 13:17 +0200
  Re: how to make a macro work as a single line if stmt without braces Bart <bc@freeuk.com> - 2024-09-21 10:13 +0100
    Re: how to make a macro work as a single line if stmt without braces Mark Summerfield <mark@qtrac.eu> - 2024-09-21 09:53 +0000
  Re: how to make a macro work as a single line if stmt without braces Ike Naar <ike@sdf.org> - 2024-09-21 09:15 +0000
    Re: how to make a macro work as a single line if stmt without braces Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-21 14:44 -0700
  Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-21 06:07 -0700
    Re: how to make a macro work as a single line if stmt without braces Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-21 15:55 -0700
  Re: how to make a macro work as a single line if stmt without braces Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-09-21 12:17 -0700
  Re: how to make a macro work as a single line if stmt without braces Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-09-21 21:18 +0000
    Re: how to make a macro work as a single line if stmt without braces Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-24 06:18 -0700

csiph-web