📜 ⬆️ ⬇️

Alternative tokens and trigraphs in C ++

Yes, yes, yes, I understand that in order to know about alternative tokens, you just have to look at paragraph 2.5 of the standard. In this sense, no one needs an article. I also remember talking about this comrade. Kaspersky.
However, I dare to suggest that not everyone knows that it is possible to write hello world on cpp like this:

%:include <stdio.h>
int main()
<%
char str<:300:> = "hello world" ;
puts(str);
return 0;
%>



Trigraphs are a little more famous thing (and I have the courage to assume that it is used somewhere). Let's display something life-affirming and relevant to the situation.
??=include <stdio.h>
??=include <cstring>
int main()
??<
bool bulinkaWantToSleep = 1;
char str??( ??) = "Amnimal what-what Up4k!??/n " ;
int i =0;
while ((i!=strlen(str))??!??!!(bulinkaWantToSleep)) //
{
putchar(str??(i++??));
}
return 0;
??>




Note: the second example should be compiled in a special way.
g++ -trigraphs main.cpp

You can read an excellent puzzle using the trigraph here: habrahabr.ru/blogs/cpp/41584

Good luck to everyone abnormal programming! By the way: I will be glad to hear about the rational use of di- and trigraphs. Perhaps code generation?

')

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


All Articles