1. (void)(((typeof((n)) *)0) == ((uint64_t *)0));
See Linux/include/asm-generic/div64.h :
No need to compare with a pointer. for type safety checks (n must be 64 bits)
Example:
n should be int , but it's short
void main() { short n; (void)(((typeof((n)) *)0) == ((int *)0)); }
We get a warning: comparison of distinct pointer types lacks cast
Compiled with: gcc -o main main.c
Compiler Version: gcc (GCC) 4.9.2 20141101 (Red Hat 4.9.2-1)
Output:
Comparing pointers is not useless. It generates a warning if the variable passed to do_div() is of the wrong type.
2. __rem
The code surrounded by braces is an expression of the gcc expression. __rem is, so to speak, the return value of do_div() .
Example:
#include <stdio.h>
Output: 9 / 2 = 4, reminder = 1
In the above example, c = do_div(a, b) equivalent to c = ({int rem = a % b; a /= b; rem;}) .
Output:
__rem not useless, this is the "return value" of do_div() .
source share