In D, `immutable(int)* x` cannot be changed by any reference to the value.
If you deceive the compiler like that, it is entitled to hand you a broken executable :-/
Besides, I forgot to mention that D immutable data is inherently thread safe, no synchronization required. And you can have as many live references to it as you like.
Immutable data is part of D's support for functional programming.
So even if you manage to reason correctly around `restrict` in C, you can't count on the compiler to translate your code correctly.
GCC also had bugs around restrict, but I don't know about their current status.
const int world = 42;
const int const * const hello = &world ;
Apparently, you can be very const and `gcc -Wall -Wextra -std=c99` won't raise any complaints. const int * const hello = &world;
Secondly, what should the compiler complain about? You have a const int, and then a const pointer to const int, pointing to that first const int. What’s the problem?Thirdly, the latest C version supported by GCC is “-std=c17”.
int main()
{
const int world = 42;
const const const int const const * const const hello = &world;
return 0;
}
Is a valid programeven if I use a magnetic needle to change the bits in my RAM ? :)