The following I have come across in the section 3.7.4.3/3:
An integer value is an integer representation of a safely-derived pointer only if its type is at least as large as std::intptr_tand it is one of the following:
[...]
— the result of an additive or bitwise operation, one of whose operands is an integer representation of a safely-derived pointer value
P
, if that result converted byreinterpret_cast<void*>
would compare equal to a safely-derived pointer computable fromreinterpret_cast<void*>(P)
.
Ok, let int *P = new int(1);
be a some pointer and long p_int = <reinterpret_cast<long>(P);
his integer representation. Consider the following code:
int *P = new int(1); //Safely-derived pointer
long p_int = <reinterpret_cast<long>(P); //Integer representation of safely derived pointer
long new_p_int = p_int + 10; // Result of an additive operation
void *new_P = reinterpret_cast<void*>(new_p_int);
void *P_cpnverting_to_void = reinterpret_cast<void*>(P);
cout << "P converted to void* = " << P_cpnverting_to_void << endl;
cout << "P after result of an additive operation = " << new_P << endl;
The rule is not clear. How can the result pointer be compare equal reinterpret_cast(P)? They never be compare equal after applying additive operation. Could you possibly provide actual example reflecting the rule?