What is the meaning of the <: in C syntax?

Possible duplicate:
<: cannot create a list of template arguments

Do you know that

 int a<:10:>; 

equivalently

 int a[10]; 

?

I wrote some piece of code where I have a global namespace and a limited namespace, such as NS1. I have a class called Module in my global namespace, and I am importing some other libraries into NS1, which also have a Module class. I tried to create std :: list of my module, that is :: Module inside a function in NS1 and to do this, I got this compilation error

 std::list<::Module*> &myModule; genllvm.cpp:60:11: error: '<::' cannot begin a template-argument list ./genllvm.cpp:60:11: note: '<:' is an alternate spelling for '['. Insert whitespace between '<' and '::' ./genllvm.cpp:60:11: note: (if you use '-fpermissive' G++ 

What is the meaning of this syntax <:?

+4
source share
4 answers

Its a call to alternative tokens. There are several of them in C ++:

  <% { %> } <: [ :> ] %: # %:%: ## and && bitor | or || xor ห† compl ~ bitand & and_eq &= or_eq |= xor_eq ห†= not ! not_eq != 

You can see that some alternative markers are made up of letters. Therefore, you can write if (a<b and b<c) in the compiler, which can correctly handle them. Their existence is due to the lack of characters in keyboards or character sets. Alternative tokens are never replaced by primary tokens (as opposed to trigraphs), but they behave in the same way as the primary one.

However, C ++ 0x requires special handling for <:: (2.5p3):

Otherwise, if the following three characters: <:: and the subsequent character is neither: nor>, <is treated as the preprocessor token by itself, and not as the first character of the alternative token <:.

So SomeTemplate<::SomeClass> can be processed correctly.

+11
source

This is for encodings that don't have [ .

ยง6.4.6-3 (C99)

In all aspects of the language, six tokens

 <: :> <% %> %: %:%: 

behave accordingly in the same way as six tokens

 [ ] { } # ## 
+8
source

This is basically a historical thing related to restrictions on the terminal and code page.

Read a short Wikipedia article on digraphs and trigraphs .

+2
source

It is called digraph . It was used when the terminals did not have some of the characters used by C.

+1
source

Source: https://habr.com/ru/post/1384055/


All Articles