Why would you use the ternary operator without assigning a value for the "true" condition?
Posted
by RickNotFred
on Stack Overflow
See other posts from Stack Overflow
or by RickNotFred
Published on 2010-05-10T20:32:43Z
Indexed on
2010/05/10
20:44 UTC
Read the original article
Hit count: 146
c
|android-emulator
In the Android open-source qemu code I ran across this line of code:
machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
It this just a confusing way of saying:
if (machine->max_cpus) {
; //do nothing
} else {
machine->max_cpus = 1;
}
If so, wouldn't it be clearer as:
if (machine->max_cpus == 0) machine->max_cpus = 1;
Interestingly, this compiles and works fine with gcc, but doesn't compile on http://www.comeaucomputing.com/tryitout/ .
© Stack Overflow or respective owner