M
Markus.Elfring
I am interested to know if the pointer value for the memory address can
be changed by a compiler if the constness of the corresponding type is
cast away.
inline char* deconstify1(char const * X) { return (char*) X; }
inline char* deconstify2(char const * X) { return const_cast<char*>(X);
}
const char source [] = "Test";
char* alias1 = deconstify1(source);
char* alias2 = deconstify2(source);
if ((source != alias1) || (source != alias2) || (alias1 != alias2))
{ printf("unequal: %p %p %p", source, alias1, alias2); }
Can this happen on a current platform?
Does any tool try to copy the data to a read-only area to achieve any
protection?
Regards,
Markus
be changed by a compiler if the constness of the corresponding type is
cast away.
inline char* deconstify1(char const * X) { return (char*) X; }
inline char* deconstify2(char const * X) { return const_cast<char*>(X);
}
const char source [] = "Test";
char* alias1 = deconstify1(source);
char* alias2 = deconstify2(source);
if ((source != alias1) || (source != alias2) || (alias1 != alias2))
{ printf("unequal: %p %p %p", source, alias1, alias2); }
Can this happen on a current platform?
Does any tool try to copy the data to a read-only area to achieve any
protection?
Regards,
Markus