Which is what any self respecting optimiser will do with a constant.
But C's const variables are not constants. Do the guarantees that
const makes actually allow the compiler to assume the variable's
value in a situation like this?[/QUOTE]
I think so -- at least, I can't see why not. Any attempt to change a
const object is UB (at least I have not seen a "hole" in the rules) so
the compiler can assume the value is unchanged by the program.
Obviously, a volatile const object can be change by something else by
that is another matter. At least two compilers I've used put const
objects in read-only memory which would be non-conforming otherwise.