[drifting over to const from a discussion of ignoring register]
I read the above twice, and apparently fail to parse it correctly.
Anyway, I would prefer that the compiler complain if constness is
violated, not otherwise. The warning I'm talking about is to the
effect that "const objects may be stored in read-only memory, and
attempts to modify them may fail." Regardless of whether any such
attempt was made. The warning has no relation to the code - it's just
spitting out a line from the programming manual.
It sounds to me like that's the compiler's way of saying "I don't do
semantics checking on const, so I might be missing a constraint violation,
so here's a diagnostic just in case", though somewhat less so now that
I've seen the actual text of the warning. (Unless it also complains
about code that actually does violate the constraints on const objects?)
Doing the equivalent with register, as I was suggesting (now snipped), is
actually a sensible thing to do for a completely-and-correctly implemented
compiler - any self-respecting optimizing compiler will ignore it during
code generation anyways, and the constraints on register objects don't
really serve any useful purpose in correctness checking.
For const, doing this means that the compiler implementor was either
too lazy or (more likely) too rushed to properly implement const (I
suspect by adding it to a pre-ANSI compiler?). Not a Good Thing, but
not entirely unreasonable either.
So my question was, would you prefer this behavior (warning when it
sees a keyword it ignores) over the behavior Ben suggested (warning
when a constraint would be violated if the object being acted on had
the storage class defined by the keyword that was being ignored)?
--------
void foo(void)
{
int a;
/*I was talking about a warning here
("register keyword ignored")
*/
register int b;
/*Ben was talking about a warning here
("register keyword may have been ignored in declaration of operand of &")
*/
do_something_with(&a);
/*This is a constraint violation; either warning above will give
the required diagnostic when this happens as well as in cases
where it doesn't
*/
do_something_with(&b);
}
--------
Note especially that I'm not claiming either behavior is "good" for
const, just that one is more reasonable than the other, for the same
reason it's more reasonable for register.
dave