RFC: C preprocessor extension: Multiline/block macro definition

NomagnoIsNotDead via Gcc <[email protected]> Fri, 24 Jul 2026 14:03:12 +0200
Newsgroups gmane.comp.gcc.devel
Message-ID <CALzUo856qtVxh8PobEG7Qkf8pp3JkxCeunx7ASbDkmKSeifxbg@mail.gmail.com>
Greetings!

I have an idea to extend the GNU C preprocessor with a new kind of
directive. Its behaviour should be sufficiently encapsulated by the
following simple example:

#startdef MACRO_NAME
    You may define multiline macros here.
    No backslashes are needed.
#enddef

Specifically, a multiline macro definition block is started by #startdef,
and any text within is interpreted as part of the macro definition. Any
appearance of #enddef at the beginning of a line within this block will
terminate the macro definition. It can be thought of as the traditional C
comment /*text*/-analogue to C++-style comments //text, but for macros.

It is a purely ergonomic feature for writing large, multi-line macros in a
slightly more maintainable manner.

I made a prototype in the form of a wrapper around cc1 with the -B command
line option that converts #startdef-#enddef blocks to regular #define s,
but that approach has clear limitations so I am starting work in an
implementation as a libcpp feature.

I know GNU C is generally open to adding certain extensions, but I also
know this feature touches one of the more forward-facing parts of GCC. So I
would like to ask for feedback and opinions before committing to making a
patch that fulfills the relatively significant requirements in the GCC
contribution guidelines for the C frontend. I am not very experienced with
contributing to large free software projects, so any advice is appreciated.

Cheers,
Alvaro Saez AKA Nomagno.