📜 ⬆️ ⬇️

C ++ for Perl programmers

There is an old joke that a programmer in FORTRAN will write in FORTRANA in any programming language.

Here is a 3-line program that is compiled by any C ++ 11 compiler, after which it normally starts and runs.
int main(){ return !<:]()<%;[=:>(){<:&](){;%>();%>();}; } 


An example in the Online IDE
In principle, this line can be used as a detector for C ++ programmers - not everyone can immediately understand how it works.

')
The post was written as a social experiment. From my point of view, a professional should thoroughly understand his instrument. If you guessed what is happening in the code - write in the comments.

In order not to lose the intrigue explanation under the spoiler:
Spoiler
 int main(){ return ![](){; [=](){ [&](){;}(); }(); }; } 

Just some characters are replaced by digraphs.
Digraphs are part of the ISO C 99 standard of digraphs . For C ++, there are still Trigraphs . True in most C ++ compilers, trigraphs are disabled by default. But sish digraphs are included.

All these * graphs appeared because the ISO / IEC 646 seven-bit code page (1972) assigned some symbols [,], {,}, ^, ~ to national ones, therefore it was necessary to ensure compatibility of the source code with the new standard. So <: is the equivalent of the opening square bracket.

Time passed, the 21st century came, everyone began to use UTF-8, but the digraphs remained in the standard. And what is most disgusting, in many legacy projects still occur. So do not be scared to see this in the old source

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


All Articles