[英]What does this 'emoji code' do?
I think this is C code, but I'm not entirely sure.我认为这是 C 代码,但我不完全确定。 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)⚠);}
Let's deobfuscate this.让我们对此进行反混淆。
enum eyes {a=1, b, c};
void f(eyes e) {exit((int)e);}
So basically it defines a function that aborts the program execution with an exit code from an enum type.所以基本上它定义了一个函数,该函数使用枚举类型的退出代码中止程序执行。
It won't work in C though.但是它在 C 中不起作用。
It's not valid C, but it might be accepted by a tolerant C++ compiler.它不是有效的 C,但它可能被宽容的 C++ 编译器接受。 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.在 C++ 中, class
、 union
、 struct
和enum
声明类型名。 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).在 C 中,您需要使用typedef
来实现大致相同的效果(大约是因为您无法在 C 的范围内声明类型名)。 So the line:所以这一行:
enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
declares a type called ಠ_ಠ
, which is an enum
with three members corresponding to constants 1
, 2
and 3
.声明了一个名为ಠ_ಠ
的类型,它是一个具有三个成员的enum
,分别对应于常量1
、 2
和3
。 (Note 1) (注1)
Since ಠ_ಠ
is a typename, it can then be used as such.由于ಠ_ಠ
是一个类型名,因此可以这样使用。 In particular, you can declare the function ┻━┻︵╰
(Note 2):特别是,你可以声明函数┻━┻︵╰
(注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.它将ಠ_ಠ
作为名为⚠
的参数(注 3),将其转换为int
,然后使用该值调用标准 C 库函数exit
。
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.枚举类型名称很好,但所有成员名称都包含不在当前 C++ 标准中有效标识符字符列表中的字符。 A tolerant C++ compiler might allow them as an extension.宽容的 C++ 编译器可能允许它们作为扩展。 (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. (但是,clang 和 gcc 都没有。)特别是,度数符号 U+00B0 °
不是有效的标识符字符,U+2570 ╰
也不是一个有效的标识符字符,光弧向上和右框绘制字符。 In fact, none of the box drawing characters are valid identifier characters, including the white square U+25A1 □
.事实上,方框图字符都不是有效的标识符字符,包括白色方块 U+25A1 □
。
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.旋转的括号也有效,但四个方框图字符无效,如上所述。
The "warning sign" ⚠
is also not on the list of valid identifier characters. “警告标志” ⚠
也不在有效标识符字符列表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.