public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Yair Lenga <yair.lenga@gmail.com>
To: gcc@gcc.gnu.org
Subject: Passing c blocks to pre processor
Date: Sat, 28 May 2022 08:48:31 +0300	[thread overview]
Message-ID: <76AFCA00-04E9-4AC7-9587-E88779AD85AE@gmail.com> (raw)

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 ‘)’.

Thanks, yair.


Sent from my iPad

             reply	other threads:[~2022-05-28  5:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-28  5:48 Yair Lenga [this message]
2022-05-28  7:40 ` Jonathan Wakely

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=76AFCA00-04E9-4AC7-9587-E88779AD85AE@gmail.com \
    --to=yair.lenga@gmail.com \
    --cc=gcc@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).