Re: Limit on maximum number of register variable in C program
From: Dave Vandervies (dj3vande_at_csclub.uwaterloo.ca)
Date: 02/25/05
- Next message: Dave Vandervies: "Re: ANSI C Newbie Question"
- Previous message: jacob navia: "Re: ANSI C Newbie Question"
- In reply to: Alan Balmer: "Re: Limit on maximum number of register variable in C program"
- Next in thread: Randy Howard: "Re: Limit on maximum number of register variable in C program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 25 Feb 2005 18:46:13 +0000 (UTC)
In article <athu11lr1ubpqm4n6nmc00tsfrc7ndcg4l@4ax.com>,
Alan Balmer <albalmer@spamcop.net> wrote:
>On Thu, 24 Feb 2005 04:16:16 +0000 (UTC), dj3vande@csclub.uwaterloo.ca
>(Dave Vandervies) wrote:
>
>>In article <s84q11hiq3f9ef4qmtv7as0gvvsiu2n7ia@4ax.com>,
>>Alan Balmer <albalmer@spamcop.net> wrote:
[drifting over to const from a discussion of ignoring register]
>>>Yechh. I have to work with a (HP-UX) compiler which issues a warning
>>>every time it sees "const", whether or not it's used properly.
>>
>>This is much less unreasonable for register than it is for const, just
>>because of the way the two are used.
>>
>>But even for const... would you prefer that the compiler warned every
>>time the code modified an object, because that object could have been
>>declared const and the compiler knew it ignored the const if there was
>>one and might therefore have missed a constraint violation?
>>
>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
-- Dave Vandervies dj3vande@csclub.uwaterloo.ca What you have in mind about trees is extremely obscure. They come in green, red-black, avl, binary, B, deciduous, non-deciduous, tropical, fruit, ornamental, just to name a few varieties. --CBFalconer in comp.lang.c
- Next message: Dave Vandervies: "Re: ANSI C Newbie Question"
- Previous message: jacob navia: "Re: ANSI C Newbie Question"
- In reply to: Alan Balmer: "Re: Limit on maximum number of register variable in C program"
- Next in thread: Randy Howard: "Re: Limit on maximum number of register variable in C program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|