1

私はこのペーストに出くわしました:

int main() {
return!!!~!!!!!~!!!1??!??!1?

"^_^"  <:3

]:     "^.-"

<:      0.0 

<3  :>  ;}

null を返すとされるかわいい顔文字のコレクション。C-fuが私のものよりも優れている人は、それがどのように機能するかを説明していますか?

4

3 に答える 3

12

<: means [, :> means ] (they're digraphs).

??! means | (it's a trigraph), so ??!??! is logical ||

The last ? on the first line is a conditional operator.

The remainder selects one character from one of the two emoticon strings. It will select from the first one, since regardless of how many ! and ~ there are in the mess at the start, anything || 1 is true.

So it actually selects "^_^"[3], which is the nul terminator at the end of the string, which is 0.

Basically the code reads return ((some mess) || 1) ? "^_^"[3] : "^.-"[1];, since 0.0 < 3 is true.

[Edit: I just realised (and commented below), it is possible to write a conforming implementation on which ~(expression equal to 0) has undefined behavior. So to know whether or not this code is strictly conforming, you have to check that neither of the ~ is applied to a zero. In fact !!!1 is 0, so the code doesn't strictly conform. It'll work on any implementation you can name, though, since approximately everything uses 2's complement.]

于 2013-04-04T10:47:31.957 に答える