W
woyt.a
Hi,
following code:
int main()
{
const size_t val0 = 0;
static const size_t val1 = 0;
// works ok
size_t* pVal0 = const_cast<size_t*>(&val0);
*pVal0 = 5;
// causes access violation errof on runtime
size_t* pVal1 = const_cast<size_t*>(&val1);
*pVal1 = 7;
return 0;
}
can change value of val0 const variable but invokes segmentation fault for val1.
This is known issue, as val1 is put in the read-only memory page.
My question is:
1. is there any way to change static cont variable value?
2. is there any way to prevent compller to put that variable in read-only memory?
Regards,
woyt.a
following code:
int main()
{
const size_t val0 = 0;
static const size_t val1 = 0;
// works ok
size_t* pVal0 = const_cast<size_t*>(&val0);
*pVal0 = 5;
// causes access violation errof on runtime
size_t* pVal1 = const_cast<size_t*>(&val1);
*pVal1 = 7;
return 0;
}
can change value of val0 const variable but invokes segmentation fault for val1.
This is known issue, as val1 is put in the read-only memory page.
My question is:
1. is there any way to change static cont variable value?
2. is there any way to prevent compller to put that variable in read-only memory?
Regards,
woyt.a