C++ Logo

liaison

Advanced search

Re: [isocpp-wg14/wg21-liaison] [isocpp-core] Octothorpes in attributes: Divergence between C and C++

From: Jₑₙₛ Gustedt <jens.gustedt_at_[hidden]>
Date: Wed, 9 Jul 2025 22:21:37 +0200
Richard,

on Wed, 9 Jul 2025 12:49:26 -0700 you (Richard Smith
<richardsmith_at_[hidden]>) wrote:

> In addition to # and ##, in the basic source character set there's
> also ` @ $ \ which satisfy the "single character that's not the start
> of another preprocessing-token" rule. EDG rejects all of those, GCC
> and MSVC reject all but $, clang accepts all.

If I understand the C standard correctly these are also all code
points that are not space and that cannot participate in valid
tokens. These are accepted in C up to phase 6. As long as they don't
reach phase 7, for example because they are eaten by a macro parameter
that is then ignored, all is fine. AFAIU in C this behavior is
intentional and there is no UB, only syntax errors in phase 7. This
allows implementations to extend the syntax and integrate for example
new punctuators in their extensions.

I know that C++ is more strict here, but I never really understood the
purpose of that.

Thanks
Jₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA antenne de Strasbourg :::::::::::::::::: Camus ::
:: INRIA PIQ program Strasbourg :::::::::: piq.inria.fr ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

Received on 2025-07-09 20:21:40