This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ alternative tokens in the preprocessor


> > #define a 1
> > #define b 2
> > #if a and b
> > int i=0;
> > #endif
> 
> Interesting.  Where can I find that in the C++ standard?

2.5., Alternative tokens. I'll try to quote it, although most of it is
a table:

1 Alternative token representations are provided for some operators
  and punctuators.16)

  Footnote 16: These include "digraphs" and additional reserved
  words. The term "digraph" (token consisting of two characters) is
  not perfectly descriptive, since one of the alternative
  preprocessing­tokens is %:%: and of course several primary tokens
  contain two characters. Nonetheless, those alternative tokens that
  aren't lexical keywords are colloquially known as "digraphs".

2 In all respects of  the language, each alternative token behaves the
  same, respectively,  as its primary  token, except for  its spelling
  17) . The set of alternative tokens is defined in Table 2.

  Footnote 17: Thus the "stringized" values (16.3.2) of [ and <: will
  be different, maintaining the source spelling, but the tokens can
  otherwise be freely interchanged.

Table 2

alternative primary alternative primary alternative primary 
______________________________________________________________ 
<%          {       and         &&       and_eq     &= 
>           }       bitor       |        or_eq      |= 
<:          [       or          ||       xor_eq     ^=
:>          ]       xor         ^        not        !
%:          #       compl       ~        not_eq     !=

> This patch has a number of problems.  The biggest one is that you've
> penalized the normal case of parse_name, since these identifiers are
> not often used.  parse_name is already a performance bottleneck for
> cpplib.

Please note that the penalty is very small. A strcmp invocation will
happen only if the identifier has the same size as the alternative
token. I can change this, but I don't think it is necessary.

> Also, remember to prevent people from re#defining these identifiers.

That already works, for

#define and 45

I get

a.cc:1:9: macro names must be identifiers

I'll see whether I can revise the patch, but it may take some weeks.

Regards,
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]