GNU's twist on ternary operator
Contents
I was recently browsing the kernel code in attempts to understand some of the weird kernel errors I see in dmesg on one of my machines.
I was a bit surprised to see an interesting syntax I have never seen before. In the following code:
|
|
(Excerpt from ucsi usb code)
What’s up with ?:
? Looks like a ternary operator with one of the values
omitted. I’ve never seen this syntax before and was a bit
confused. Turns out this is a GNU
extension.
|
|
In the example above, x will have the value of i(123), since its value is non-zero. On the other hand, y will be assigned the value of 1000.
Of course, this is a non-portable code which relies strictly on GNU extensions.