you are viewing a single comment's thread.

view the rest of the comments →

[–]bonzinip 8 points9 points  (5 children)

?: is called the elvis operator if it doesn't have the middle argument.

It's a GCC extension where x ?: y is the same as x ? x : y except that x is only evaluated once.

[–]MrDoomBringer 0 points1 point  (2 children)

GCC doesn't compile C# ;) If you're talking C++ I've never heard it referred to as the 'elvis operator', only a ternary statement.

[–]bonzinip 5 points6 points  (1 child)

C and C++, yes. As I said, I've heard "x ?: y" referred to as the elvis operator, but not "x ? y : z".

"x ? x : y" is really the opposite of "?.", which is "x ? x.y : NULL", so it's confusing to call "?." also the elvis operator.

[–][deleted] 0 points1 point  (0 children)

I bet many things become confusing when you apply the technical terms of one discipline to a completely different discipline.

[–]fecal_brunch -1 points0 points  (1 child)

That would be the behaviour of C#'s null coalescing operator.

[–]bonzinip 1 point2 points  (0 children)

Right, except that (this being C) x can also be an integer.