c++ - Cryptic line "??!??!" in legacy code -


this question has answer here:

i refactoring very old legacy code full of bugs , questionable practices, @ least modern standards. ran across 1 line cannot decipher:

p , k of type int *

return p??!??!k?p?*p:sizeof(*k):0; 

when saw not believe eyes - know ? operator, syntax bool ? trueresult : falseresult , ?? operator neither make sense (lazy evaluation not apply here), not find reference of mysterious operator anywhere.

it cool if shed light on matter.

it's called trigraph:

c11(iso/iec 9899:201x) §5.2.1.1 trigraph sequences

before other processing takes place, each occurrence of 1 of following sequences of 3 characters (called trigraph sequences17)) replaced corresponding single character.

??=    # ??(    [ ??/    \ ??)    ] ??'    ^ ??<    { ??!    | ??>    } ??-    ~ 

it's in c++11(iso/iec 14882:2011) § 2.3 trigraph sequences

so after trigraph replacement, line return p??!??!k?p?*p:sizeof(*k):0; turns into

return p || k ? p ? *p : sizeof(*k) : 0 

since ternary operator has rather low precedence, it's actually:

return (p || k) ? (p ? (*p) : sizeof(*k)) : 0; 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -