objective-c – 这是三元条件?:正确(Objective)C语法?

我不认为这是可能的,但显然在目标C它是允许:

int a = b ?: c;

所以你看到他们在这里做什么,他们抛弃了三元表达式的第二部分,如果b是非零的,b被用作第二部分。

它很聪明,但据我所知,这是针对K& R C,可能是ANSI C.

如果没有,我已经错过了一个非常聪明的语法技巧多年…唉!

更新:
它是gcc。

http://en.wikipedia.org/wiki/%3F%3A

A GNU extension to C allows omitting the second operand, and using implicitly the first operand as the second also:

06000

The expression is equivalent to

06001

except that if x is an expression, it is evaluated only once. The difference is significant if evaluating the expression has side effects.

http://stackoverflow.com/questions/8760561/is-this-ternary-conditional-correct-objective-c-syntax

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:objective-c – 这是三元条件?:正确(Objective)C语法?