C++ Logo

std-proposals

Advanced search

Re: [std-proposals] condexpr: new syntax for preprocessor conditional inclusion

From: Michael Levine <melevine45_at_[hidden]>
Date: Wed, 14 Dec 2022 21:13:53 -0500
>
>
> Message: 1
> Date: Tue, 13 Dec 2022 08:21:35 +0100
> From: Peter Olsson <dataapa_at_[hidden]>
> To: std-proposals_at_[hidden]
> Subject: Re: [std-proposals] condexpr: new syntax for preprocessor
> conditional inclusion
> Message-ID:
> <
> CADfZiqtzsNZRb-+tiP-cnZqQ6izBDOfdN1nAEe5NQdVLjWWtNQ_at_[hidden]>
> Content-Type: text/plain; charset="UTF-8"
>
> > condexpr if (ABCD)
>
> Is this equivalent to `#ifdef ABCD` or `#if ABCD` ?
>
#ifdef ABCD is equivalent to #if define ABCD. My current proposal
technically means to include both. I would consider all of these
acceptable:
 condexpr if (ABCD) // replacement syntax for #ifdef ABCD or #if define
ABCD
condexpr if (ABCD == 2) // replacement syntax for #if ABCD == 2 (an
expression, rather than just an identifier)
and the combination of both checks via:
condexpr if (ABCD && ABCD == 2) // equivalent to #ifdef ABCD ; #if ABCD == 2

A 2nd possible syntax could replace the `condexpr if (ABCD)`, with
`condexpr if (defined ABCD)` // slightly more verbose but closer to the
current `#if defined ABCD` syntax.
Similarly, `condexpr if (ABCD && ABCD == 2)` could be replaced with
`condexpr if (defined ABCD && ABCD == 2)` to further highlight the
difference in the parameters between identifier checks and expressions
without requiring an implicit identifier check as the first version would.

>The syntax looks more like standard C++ code and less like preprocessor
> directives
>
> Is this an advantage or a disadvantage?
>
> If I understand your proposal correctly, it's still a preprocessor
> directive but it disguises itself as normal C++ code. Preprocessor
> code and normal C++ code are essentially two independent languages.
> The way it works at the moment is that the preprocessor runs first
> (without it having to care about scopes or other C++ rules). The
> actual C++ code is not parsed until after the preprocessor has
> finished. Since they are so different I wonder if it's not a good
> thing that they have different syntax.
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
>
> ------------------------------
>
> End of Std-Proposals Digest, Vol 45, Issue 18
> *********************************************
>

Received on 2022-12-15 02:14:06