Mail Archives: djgpp/2001/07/18/13:15:04
Prashant Ramachandra <rprash AT wilco-int DOT com> wrote:
> I have a question that's probably got nothing to with DJGPP, so please
> forgive me for this off-topic post.
> I tried the program below and interestingly, it gives me...
> "Constant is 10. It is actually 1"
That program is very incorrect. It causes undefined behaviour at the
point of the cast from (const int *) to (int *). Gcc would have warned
you about this, if only you had asked for assistance (rule of thumb:
always use '-Wall' unless you have very good reasons not to).
> Shouldn't gcc not make the assumption that the value of j *is* 10 and
> instead reference itfrom memory instead.
No, it shouldn't. You'll have to make up your mind: either j *is*
constant, or it isn't. You can't have it both ways.
If you lie to the compiler like in this piece of source code, _you_
take responsibility for all consequences.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -