N
Nephi Immortal
I thought I want to add. Let’s look at my code below.
int main()
{
const char* data = "0123456789";
const_cast< char* >( data )[ 2 ] = 'A';
return 0;
}
C++ Compiler will compile without any problems, but it is unaware of the 4Kmemory page if it is marked as read only, but not read-write. The undefined behavior is possible. If you use Microsoft’s Virtual Memory functionsor Heap Memory functions, you have to be careful to mark either read only or read-write.
The Visual C++ will automatically compiles all constant strings into 4K memory page and it marks them as read only. What happen if you take away constant string by using const_cast? The C++ Compiler will compile fine, but the program will crash during the execution. The error dialog box will appear to the screen as saying violation memory access. You are not permitted to modify constant strings in read only 4K memory page.
I am supposed to take your advice. I should use two classes as const classand non-const class instead of one const / non-const class.
int main()
{
const char* data = "0123456789";
const_cast< char* >( data )[ 2 ] = 'A';
return 0;
}
C++ Compiler will compile without any problems, but it is unaware of the 4Kmemory page if it is marked as read only, but not read-write. The undefined behavior is possible. If you use Microsoft’s Virtual Memory functionsor Heap Memory functions, you have to be careful to mark either read only or read-write.
The Visual C++ will automatically compiles all constant strings into 4K memory page and it marks them as read only. What happen if you take away constant string by using const_cast? The C++ Compiler will compile fine, but the program will crash during the execution. The error dialog box will appear to the screen as saying violation memory access. You are not permitted to modify constant strings in read only 4K memory page.
I am supposed to take your advice. I should use two classes as const classand non-const class instead of one const / non-const class.