Search code examples
c++cunicodeidentifierdeobfuscation

What does this 'emoji code' do?


I think this is C code, but I'm not entirely sure. I found it in a few persons' online signatures, and in SO chat once. I tried compiling it, but received a really hard to read error taking issue with the unusual characters presented.

Does it do anything? I have no idea what to do with this in my head.

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}

Solution

  • It's not valid C, but it might be accepted by a tolerant C++ compiler. If so, it doesn't "do" anything; it only declares a datatype and defines a function.

    In C++, class, union, struct and enum declare typenames. In C, you need to use a typedef to achieve approximately the same effect (approximately, because you can't declare a typename in a scope in C). So the line:

    enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
    

    declares a type called ಠ_ಠ, which is an enum with three members corresponding to constants 1, 2 and 3. (Note 1)

    Since ಠ_ಠ is a typename, it can then be used as such. In particular, you can declare the function ┻━┻︵​╰ (Note 2):

    void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
    

    which takes a ಠ_ಠ as an argument named (Note 3), casts it to an int and then calls the standard C library function exit with that value.


    Notes

    1. The enum typename is fine, but all of the member names include characters not on the list of valid identifier characters in the current C++ standard. A tolerant C++ compiler might allow them as an extension. (However, neither clang nor gcc do.) In particular, the degree symbol U+00B0 ° is not a valid identifier character, and neither is U+2570 , the light arc up and right box drawing character. In fact, none of the box drawing characters are valid identifier characters, including the white square U+25A1 .

    2. Most of those characters are not valid identifier characters. There are six characters in that name: three heavy box drawing characters, a vertical left parenthesis, a zero-width space, and a light box drawing character. Curiously, the zero-width space is a valid identifier character even though it is more or less invisible. The rotated parenthesis is also valid, but the four box-drawing characters are not, as mentioned above.

    3. The "warning sign" is also not on the list of valid identifier characters.