C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Preprocessor multi-line macroes

From: Alejandro Colomar <une+cxx_std-proposals_at_[hidden]>
Date: Thu, 25 Jun 2026 00:30:38 +0200
[CC += Martin]

Hi Jens, Frederick,

On 2026-06-24T23:44:06+0200, Jens Maurer via Std-Proposals wrote:
>
> Did you run this past WG14? What's their interest?

Several of us are quite interested. I've authored a paper (two
N-numbered revisions of it, plus a few more that I've sent only in the
mailing list). Here's the latest N document:
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3531.txt>

> Jens
>
>
> On 6/24/26 23:33, Frederick Virchanza Gotham via Std-Proposals wrote:
> > Instead of doing this:
> >
> > #define ASSERT_EQ(a, b) \
> > do \
> > { \
> > if ( (a) == (b) ) break; \
> > \
> > std::fprintf(stderr, #a " != " #b " at %s:%d\n", \
> > __FILE__, __LINE__); \
> > std::abort(); \
> > } while (0)
> >
> > Wouldn't it be nice to be able to do this:
> >
> > #define ASSERT_EQ(a, b) \\\
> > do
> > {
> > if ( (a) == (b) ) break;
> >
> > std::fprintf(stderr, #a " != " #b " at %s:%d\n",
> > __FILE__, __LINE__);
> > std::abort();
> > } while (0)
> > \\\

We must use a directive for dealing with the preprocessor.
The proposal we're considering uses #def and #enddef (which is
consistent with the other group we have in the preprocessor: #if and
#endif):

 #def ASSERT_EQ(a, b)
 do
 {
  if ((a) == (b))
   break;

  fprintf(stderr, #a " != " #b " at %s:%d\n", __FILE__, __LINE__);
  abort();
 } while (0)
 #enddef

There's even some prior art in some little-known or experimental
preprocessors. We need to contact them to ask them about their
experience with this.
<https://github.com/facebookresearch/CParser#multiline-macros>
<https://www.cs.cornell.edu/andru/mlm.html>

Also, the proposal is blocked due to some refactor that we need to apply
first in the existing standard, to make it easier to specify this.
I expect we'll be able to vote this in a year or two.

I will try to put some priority to this. I'll start contacting the
authors of those preprocessors today.

> > I'm told back in the 1990's, a guy called Andrew Myers made a patch
> > for GNU gcc so that you could do:
> >
> > #begin define swap(x,y,T)
> > do {
> > T temp = x;
> > x = y;
> > y = temp;
> > } while (0)
> > #end
> >
> > Whether we use three backslashes or "'#begin define", this should be
> > standardised in C++29.

Yup, that's in the prior art we know. That's one of the people I need
to contact.

Interestingly, I very much prefer the syntax from Andrew to yours, since
Andrew at least uses preprocessing directives (#). Why did you think
'///' would be a better delimiter?


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es>

Received on 2026-06-24 22:30:57