From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by sourceware.org (Postfix) with ESMTPS id 354753858D32 for ; Tue, 26 Jul 2022 08:55:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 354753858D32 Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-31f445bd486so16586357b3.13 for ; Tue, 26 Jul 2022 01:55:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc; bh=mvmVm3oMmsi7aYqZzRdPgLXBmvTX4ZEpGN+yNU9wJIo=; b=6Bu3Wg6QYGCYnCZp/Pxgks2nxfA41T7LorU+tRGHGzHexi6s5QzE+0/gvR0VHYoqyF 1wpxD5kBNWRnLQPvFZ5DNwofmo53+KbLtsaqCbKGkX3w4w2axqORqxr8voBE+Fw0INou iiq+YyaKM7WF1zbTUMZzIG04sQ1CtACi8R7iPLxGyY/5MsiQc6jVAHkDXBetqlH1Wjbl TKx0bZV+3uqNErZ4+tk8LSRHnNeIrBENBRTbep1+W308ljv3mqcIZvef4gFdrDKOKYAO q3BQgKSQSkndhz2c/4iqktpkiiVnbhZ/rZJcxB+8OxKBryK8EG/44oH7Hp622bD2oEiB gzlQ== X-Gm-Message-State: AJIora9slmdOve8K6jRMnfihWYCEf+XUoV1yyeTu6tXEzyaUjJfdX6Po uQGWSM2N6xS5unrHaYPf/btDl4yMissP97TONYctRr74208= X-Google-Smtp-Source: AGRyM1sCv47qJneEe4oDLH5E6pvHN0jpW9iETJQ3yIHd04xViYOxZ5nObcSNXndQ5rdJGk3g5DK4rWPhJEfwMxjiBo0= X-Received: by 2002:a0d:d652:0:b0:31f:4443:968c with SMTP id y79-20020a0dd652000000b0031f4443968cmr2650501ywd.468.1658825723268; Tue, 26 Jul 2022 01:55:23 -0700 (PDT) MIME-Version: 1.0 From: Yair Lenga Date: Tue, 26 Jul 2022 11:55:13 +0300 Message-ID: Subject: C pre-processor: Better grammar for multi-line macros To: Yair Lenga via Gcc X-Spam-Status: No, score=0.6 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 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" 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: Tue, 26 Jul 2022 08:55:25 -0000 Hi, I'm trying to get community feedback for a proposal to enhance the C preprocessor support for multi-line macros. For this discussion, I prefer to put aside the philosophical debate about using macro vs generics - I'm assuming preprocessor macros are a valid solution to implement generic logic (and other constructs) that are not part of the "C" language. Summary: When implementing long macro that can not be practical expressed in a single line, one must use escaped new lines to implement the macros. This result in hard to maintain code - it's not possible to move code between regular functions, and macro functions. Also, it is hard to enter comments, or format the code for readability, as each unescaped newline will break macro definition. Proposing: adding a new directive '#macro' which will define a multi-line macro. The macro body will end with "#endmacro". (Similar to #if ... #endif). For example, a macro to count the number of elements that match a specific condition, using statement expressions. This is a relatively simple example, as there are macros that span > 30 (or more) lines in various projects. --- #macro count_if(array, length, item, condition) ({ int count = 0 ; for (int i=0 ; i