Why would you use the ternary operator without assigning a value for the “true” condition (x = x ?: 1)

前端 未结 7 1649
旧时难觅i
旧时难觅i 2020-12-03 09:38

In the Android open-source qemu code I ran across this line of code:

machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */

相关标签:
7条回答
  • 2020-12-03 10:29

    The K&R BNF shows an expression is required between "?" and ":". I don't think gcc should be compiling that without a diagnostic.

    0 讨论(0)
提交回复
热议问题