The interpretation -1as a pointer is architecture dependent and therefore unreliable.
In general, it is memsetintended to set bytes, not pointers. C makes no guarantees as to how individual bytes are combined to make a pointer. Even if your solution works, you will have to document how and why it works.
The best idea when it NULLis a valid value is to set all the pointers to the patrol of the appropriate type. So, if your structure has a field int *ip:
static const int sentineli;
foo->ip = (int *)&sentineli;
then compare with this value. This is self-documenting.
source
share