Well you can only compare things that are comparable in nature. Integers and addresses are too different to be comparable; integers are values, while addresses are pointers to values, their usages are too different to consider them comparable.
NULL
is defined as ((void *)0)
which is a special constant for pointers that denotes a pointer that never points to something... It is typed as a pointer. void *
is the universal type for pointers.
\1
is a constant for char
(it is the character of index 1 in the ASCII table, it is known as SOH char). A char is roughly a number that can be easily translated to a char when printed. You literal is 1 typed as a char, but for efficiency, in almost all arithmetic and comparison expressions, every such char is converted to an int
.
So you basically compare a pointer to an int as the compiler says. This is not strictly forbidden, but the compiler as usual has a serious doubt about this and warns you. Effectively, you expression has no sense.
If you really want to compare both (again probably non sense), then you can either:
- convert the pointer to an int (this is dangerous as you surely lose information in that conversion) : `((int)NULL) == '\1',
- convert the literal value to a pointer (less dangerous but also stupid) : `NULL == (void *)'\1'