I remember reading somewhere that C's 'const' keyword is almost useless,
except for maybe triggering some additional compiler warnings. 'Useless' as
in: a conforming C compiler cannot assume that a variable declared const is
actually constant (never modified), because it is valid to cast the const
modifier away e.g.
const int foo = 2;
int *bar;
bar = (int *)&foo;
*bar = 4;
Is that correct?
except for maybe triggering some additional compiler warnings. 'Useless' as
in: a conforming C compiler cannot assume that a variable declared const is
actually constant (never modified), because it is valid to cast the const
modifier away e.g.
const int foo = 2;
int *bar;
bar = (int *)&foo;
*bar = 4;
Is that correct?
Comment