I was reading through the QEMU source code when I encountered a piece of code like below :-
CPUState *cpu_by_arch_id(int64_t id)
{
CPUState *cpu;
CPU_FOREACH(cpu) {
CPUClass *cc = CPU_GET_CLASS(cpu);
if (cc->get_arch_id(cpu) == id) {
return cpu;
}
}
return NULL;
}
bool cpu_exists(int64_t id)
{
return !!cpu_by_arch_id(id);
}
The function cpu_exists is a boolean function that returns the value returned by the function cpu_by_arch_id(after applying the operator !!). The cpu_by_arch_id
returns a pointer to a specific QEMU struct as you can see. I am finding it quite hard to understand how using the !! operator to the return value converts it into a boolean value.
What is the specific purpose of using the "!!"- double negation operator here ?