I saw some code looking like this:
Object *area = new Object[n];
memset(area, 0xff, sizeof(Object) * count);
So this fills the Object array's every field with bit 1. Then later there are multiple places checking if an object's field has not been filled yet by checking against ~0 (negative zero):
const unsigned int NULL_INDEX = ~0;
...
if(object.field == NULL_INDEX) {...}
The field on that Object class is unsigned int type. I'm confused that why 0xff can be evaluated to be equal to ~0, on unsigned int? I saw another post talking about 0xff equals -1 on 2's complement system, and found another post which I think it means that whether a C++ program interprets 0xff to be -1 or ~0 is system dependent?
What exactly is the portable way in C++ to check for integer when filled with 0xff? Should this be checked against unsigned int or signed int? I'm so confused...