9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Dan Cross <crossd@gmail.com>
To: 9front@9front.org
Subject: Re: [9front] [PATCH] Fix assert macro to not break on commas
Date: Mon, 27 Nov 2023 10:59:06 -0500	[thread overview]
Message-ID: <CAEoi9W4Dg=AYwj2gpNm0LB88P1ak=gWOb=CgEUY+gWFkuSGeAA@mail.gmail.com> (raw)
In-Reply-To: <B97E8AA42E8B987F42A2D8863AE4AEB9@eigenstate.org>

On Mon, Nov 27, 2023 at 10:40 AM <ori@eigenstate.org> wrote:
> Quoth Blue-Maned_Hawk <bluemanedhawk@gmail.com>:
> > On 11/26/23 19:00, ori@eigenstate.org wrote:
> > > Quoth Blue-Maned_Hawk <bluemanedhawk@gmail.com>:
> > >> On 11/26/23 17:52, ori@eigenstate.org wrote:
> > >>> Quoth Blue-Maned_Hawk <bluemanedhawk@gmail.com>:
> > >>>> What reason have y'all for avoiding macros?
> > >>>
> > >>> Well, the fact that you need hacks like the one that started this
> > >>> thread, for one;
> > >>
> > >> I don't see how it's a hack, but maybe i've just become numb to macro
> > >> shenaniganry.
> > >>
> > >>>                   what if you had  macro that took *two* arguments?
> > >>>
> > >>>   #define assert_msg(cond, msg) \
> > >>>           ...what here?
> > >>>
> > >>> I don't see how you can avoid just saying "it's a macro, it's going
> > >>> to be weird, don't even try".
> > >>>
> > >>
> > >> Don't even try writing the macro or don't even try making it not weird?
> > >> Because i can thing of a way to define such a thing:
> > >>
> > >>    #define assert_msg(cond, msg) ((cond) ? (void)0 : (print(msg), exits(msg)))
> > >>
> > >> and i don't think that that's a particularly weird way to do so.
> > >
> > >
> > > Wouldn't that fall apart on the same case that you showed above?
> > >
> > >     assert_msg((Thing){0, 1}.a, "foo");
> > >
> >
> > Aye, correct you are.  In that case, it could be rearranged to
> >
> >       #define assert_msg(msg, ...) ((__VA_ARGS__) ? (void)0 : (print(msg),
> > exits(msg)))
> >
> > and it would be able to tolerate unparenthesized commas in the checked
> > expression.
>
> assert_msg((Thing){0, "foo"}.a, (Thing){1, "bar"}.b);

It seems like one could keep going with more complex macros and every
expanded use on those macros to demonstrate that the way program text
is parsed in the preprocessor and the language proper is different.
But this is getting a bit far away from the original change
suggestion, which was substituting three symbols in a single macro for
a different three symbols. Whether that's worth it just to avoid a set
of parentheses when using the comma operator or a struct literal in an
`assert` is debatable, but the difference in complexity is pretty much
negligible.

Regardless, I'd suggest that almost no one implements `assert()` the
suggested way, and it would be just another gratuitous difference
between the C used here and the rest of the world; that alone is
enough to reject the patch (to me anyway; you all do you).

        - Dan C.

  reply	other threads:[~2023-11-27 16:02 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22 23:11 Blue-Maned_Hawk
2023-11-23  4:20 ` Jacob Moody
2023-11-25  0:27   ` Blue-Maned_Hawk
2023-11-25  1:09     ` Jacob Moody
2023-11-25  4:34     ` ori
2023-11-25 12:09       ` Blue-Maned_Hawk
2023-11-25 18:46         ` Kurt H Maier
2023-11-25 20:06           ` Steve Simon
2023-11-25 20:39             ` Dan Cross
2023-11-25 22:47               ` Steve Simon
2023-11-26  2:22               ` Kurt H Maier
2023-11-26 17:31                 ` Blue-Maned_Hawk
2023-11-26 18:13                   ` ori
2023-11-26 22:39                     ` Blue-Maned_Hawk
2023-11-26 22:52                       ` ori
2023-11-26 23:30                         ` Blue-Maned_Hawk
2023-11-27  0:00                           ` ori
2023-11-27 11:20                             ` Blue-Maned_Hawk
2023-11-27 15:38                               ` ori
2023-11-27 15:59                                 ` Dan Cross [this message]
2023-11-27 22:21                                 ` Blue-Maned_Hawk
2023-11-27 23:59                                   ` ori
2023-11-28  0:30                                     ` Blue-Maned_Hawk
2023-11-28  0:34                                       ` ori
2023-11-29  9:14                                         ` Blue-Maned_Hawk
2023-11-26 19:58                   ` Kurt H Maier
2023-11-26 22:37                     ` Blue-Maned_Hawk
2023-11-25  4:49     ` ori
2023-11-26 18:59     ` Amavect
     [not found]       ` <7025e6e9-fca5-4648-aaea-a80260c35739@sirjofri.de>
2023-11-26 21:11         ` sirjofri
2023-11-26 22:41       ` Blue-Maned_Hawk
2023-11-27 15:44         ` Amavect
2023-11-26 22:36 ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEoi9W4Dg=AYwj2gpNm0LB88P1ak=gWOb=CgEUY+gWFkuSGeAA@mail.gmail.com' \
    --to=crossd@gmail.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).