When it comes to some macro functions defined in the Linux kernel, I can find some weird ternary operator with always true condition (1)
#define to_cpumask(bitmap) \
((struct cpumask *)(1 ? (bitmap) \
: (void *)sizeof(__check_is_bitmap(bitmap))))
static inline int __check_is_bitmap(const unsigned long *bitmap)
{
return 1;
}
It seems that __check_is_bitmap(bitmap) function will not be invoked at any condition because it is written with ternary operator condition 1.
It seems that to check the type of bitmap at the compile time, this macro function intentionally has introduced a function, __check_is_bitmap, that requires an unsigned long pointer parameter, even though it will not be invoked.
If it wants to check the parameter type requirement, it would have been better to use an inline function or just plain function. Why the kernel programmers prefer the #defined function compared to inline function in this case?