!!
negates a boolean expression twice, essentially converting an expressions value to 0
or 1
.
As in C all values other than zero mean true, and zero means false, !!
can be used to convert it into 0
or 1
, in the case you need to use it later in a function or expression which doesn't accept any value for true, only the number 1
.
About the rest: unsigned
interprets the internal representation of your int a
from your function argument to unsigned int
, so for example -1
becomes 4294967295
if your compiler uses two's complement and 4 byte ints.
About the casting to long
: I strongly recommend against in similar situations unless you absolutely know what you are doing. In your example, it does some pointer arithmetic, in interpreting your pointer as numeric values, essentially working with the addresses of your variables as if they were just numbers. They have probably chosen long
because on their system it had the exact same size as a pointer. This is not guaranteed to be so on all systems.
So, to give a very short answer to your question: The code does undefined behavior with those expressions, except for the !!
which just give 0
if the expression was zero, and 1
otherwise.