From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Yair Lenga <yair.lenga@gmail.com>
Cc: "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: Passing c blocks to pre processor
Date: Sat, 28 May 2022 08:40:18 +0100 [thread overview]
Message-ID: <CAH6eHdQ6knMcG0rGc+qjH7_eVLoLjxhhn6t5NDB9Xy7ifGFXVQ@mail.gmail.com> (raw)
In-Reply-To: <76AFCA00-04E9-4AC7-9587-E88779AD85AE@gmail.com>
On Sat, 28 May 2022, 06:49 Yair Lenga via Gcc, <gcc@gcc.gnu.org> wrote:
> Hi,
>
> I am trying to define macros that will accept code blocks. This will be
> used to create high level structures (like iterations, etc.). Ideally, I
> would like to do something like (this is simplified example, actual code
> much more application specific):
>
> Foreach(var, low, high, block)
>
> While should translate to:
> For (int var=low ; var < high ; var ++) block
>
> The challnge is the gcc pre processor does not accept blocks. It assume a
> comma terminate a block. For example:
> Foreach(foo, 1, 30, { int z=5, y=3, …}) will invoke the macro with 5
> arguments: (1) foo (2) 1, (3) 30, (4) { int z=5}, (5) y=3,
>
> Is there a way to tell CPP that an argument that start with ‘{‘ should
> extend until the matching ‘}’ ? Similar to the way ‘(‘ in macro arguments
> will extend till matching ‘)’.
>
This question seems off-topic on this mailing list, as it's not about GCC
development. It would be more suited to the gcc-help list.
I don't think you can do that. You need to use __VA_ARGS__ to accept
arbitrary code containing commas. You could look at how the
Boost.Preprocessor library works.
prev parent reply other threads:[~2022-05-28 7:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-28 5:48 Yair Lenga
2022-05-28 7:40 ` Jonathan Wakely [this message]
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=CAH6eHdQ6knMcG0rGc+qjH7_eVLoLjxhhn6t5NDB9Xy7ifGFXVQ@mail.gmail.com \
--to=jwakely.gcc@gmail.com \
--cc=gcc@gcc.gnu.org \
--cc=yair.lenga@gmail.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).