Bizarre use of conditional operator in Linux

后端 未结 4 1790
长发绾君心
长发绾君心 2020-12-05 23:23

In the 3.0.4 Linux kernel, mm/filemap.c has this line of code:

retval = retval ?: desc.error;

I\'ve tried compiling a similar minimal test

4条回答
  •  感情败类
    2020-12-05 23:30

    It's a gcc extension. x ?: y is equivalent to x ? x : y --- see http://gcc.gnu.org/onlinedocs/gcc/Conditionals.html#Conditionals.

    Yes, I think it's evil too.

提交回复
热议问题