I have come across the following code in the Linux Kernel source (2.6.32).
do_wait_for_common(struct completion *x, long timeout, int state)
{
if (!x->done) {
/* some code here */
}
x->done--;
return timeout ?: 1; <--- What it returns?
}
To understand the behavior, I have manually tried the following code
#include <stdio.h>
int f(int x)
{
return x?:1;
}
int main()
{
printf("f %d\n", f(0));
printf("f %d\n", f(1));
return 0;
}
And got the following output
f 1
f 1
And when I change it to
int f(int x)
{
return x?:2;
}
I am getting
f 2
f 1
I just want to know whether this behavior (return 1 if nothing mentioned) is mentioned in the standard.