相关疑难解决方法(0)

在Linux中奇怪地使用条件运算符

在3.0.4 Linux内核中,mm/filemap.c有这行代码:

retval = retval ?: desc.error;
Run Code Online (Sandbox Code Playgroud)

我已经尝试用gcc -Wall编译一个类似的最小测试用例,并且没有得到任何警告; 行为似乎与:

retval = retval ? retval : desc.error;
Run Code Online (Sandbox Code Playgroud)

看看C99标准,我无法弄清楚正式描述这种行为的原因.为什么这样好?

c linux gcc c99

37
推荐指数
3
解决办法
1850
查看次数

是什么 "?" 和":"序列实际上被称为?

这可能是一个傻瓜问题,但我无法弄清楚? exp : other_exp序列的调用.

例:

int result = (true) ? 1 : 0;

我已经尝试过使用谷歌机器了,但是在不知道它叫什么的情况下Googilize很难做到.

谢谢!

c++ idioms conditional-operator

5
推荐指数
1
解决办法
1678
查看次数

标签 统计

c ×1

c++ ×1

c99 ×1

conditional-operator ×1

gcc ×1

idioms ×1

linux ×1