Modifying an object via a const lvalue is a constraint violation; any
program that does this is not a valid C program.
Is the compiler able to use that for optimizations (eg. hold
const variables in registers, etc) ?
Well, it's forbidden, GCC will give an error.
But I suppose you mean if GCC can use the const-ness of objects
to direct optimisation? It can.
Modifying a const object via a non-const lvalue is undefined
behaviour.
Is there a flag to forbid that ?
It's always forbidden, but it cannot always be detected; halting
problem and all that.
Segher