From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 87FB93857B9B for ; Sat, 28 May 2022 07:40:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 87FB93857B9B Received: by mail-wr1-x429.google.com with SMTP id e2so8481088wrc.1 for ; Sat, 28 May 2022 00:40:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=U2SWai7qep6sRkaxPYKrtrOFKI9PAe8iSaEHHj1rEIQ=; b=HxvlrgUuSCko6Xqepx43gqFGQBci23iGzCliJtrUhHEZetyeZnPUWuN/dz7hfGBZe5 8Ws+fB4caEHccTTjfVuaP7XIZsZ4uQ3kJGrJsD8t3QmXRjHEvtjpnfkYgO2p0BKn3b46 jg2aCH0YCkFdenY73cHsPS35Sh7tvzaven+tzPNoOyuqvK6UrkZ1YuKsAJ3OwldPN1AY ZIuz6B532q5P7Zj4C7b2Y5K49vND6CI7pmkeXxA6K88kxMs/aKfdbGa8+2erA/62yvJd u5ZcvLxvgNT0xf4IQcGnJBeEFBI3wcZ038vF4Q2bAFzVJ9zyx5S9DMdlkrG45AVTzM93 veQA== X-Gm-Message-State: AOAM530PqmSluX42tFDfF08vYtd6iJbXPXZfuLwJ1UDyayUcyJ1Ni1x6 iQ23Cwia23I2D7oXT1iE0Z2RTdTSyqB2PwhOVxg= X-Google-Smtp-Source: ABdhPJwkOz3WK3KmqW+zPT1TjBQZDeAKKVsZzWLD2Tmvl287uLMpAQ/ynq/E4BS03MYVsAhEAbkqaxGRGkEHVFltE2E= X-Received: by 2002:a5d:6d8f:0:b0:20c:7fb7:d59c with SMTP id l15-20020a5d6d8f000000b0020c7fb7d59cmr40175447wrs.77.1653723629151; Sat, 28 May 2022 00:40:29 -0700 (PDT) MIME-Version: 1.0 References: <76AFCA00-04E9-4AC7-9587-E88779AD85AE@gmail.com> In-Reply-To: <76AFCA00-04E9-4AC7-9587-E88779AD85AE@gmail.com> From: Jonathan Wakely Date: Sat, 28 May 2022 08:40:18 +0100 Message-ID: Subject: Re: Passing c blocks to pre processor To: Yair Lenga Cc: "gcc@gcc.gnu.org" X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2022 07:40:32 -0000 On Sat, 28 May 2022, 06:49 Yair Lenga via Gcc, 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=3Dlow ; 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=3D5, y=3D3, =E2=80=A6}) will invoke the macro= with 5 > arguments: (1) foo (2) 1, (3) 30, (4) { int z=3D5}, (5) y=3D3, > > Is there a way to tell CPP that an argument that start with =E2=80=98{=E2= =80=98 should > extend until the matching =E2=80=98}=E2=80=99 ? Similar to the way =E2=80= =98(=E2=80=98 in macro arguments > will extend till matching =E2=80=98)=E2=80=99. > 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.