Related articles |
---|
Improved C warning messages mikov@usa.net (Tzvetan Mikov) (1999-04-22) |
Re: Improved C warning messages jejones@microware.com (James Jones) (1999-04-26) |
Re: Improved C warning messages gopi@sankhya.com (1999-04-26) |
Re: Improved C warning messages rinie4384@my-dejanews.com (1999-04-26) |
Re: Improved C warning messages fjh@cs.mu.OZ.AU (1999-04-29) |
Re: Improved C warning messages mikov@usa.net (Tzvetan Mikov) (1999-04-29) |
Re: Improved C warning messages mikov@usa.net (Tzvetan Mikov) (1999-04-29) |
Re: Improved C warning messages saroj@bear.com (1999-04-30) |
From: | rinie4384@my-dejanews.com |
Newsgroups: | comp.compilers |
Date: | 26 Apr 1999 02:07:15 -0400 |
Organization: | Deja News - The Leader in Internet Discussion |
References: | 99-04-080 |
Keywords: | C, errors |
"Tzvetan Mikov" <mikov@usa.net> wrote:
> Here is an example (it is taken from a discussion in another newsgroup):
>
> unsigned short c;
> unsigned short d;
> ...
> d = c >> 8; // warning: assigning int to short
> s = u >> 16; // must not produce warning about assigning int to short
>
> If the shift count was 15, the warning would be completely relevant however.
>
> The task gets a little more complicated because so far I have
> abstracted the front end from the target CPU. It operates with
> variable type sizes (e.g. "int" might be or might not be equal to
> "long", etc.) It gets even more interesting if signed and unsigned
> bitfields are involved.
You can solve this by letting the frontend know the int size as a
parameterised table (so that you can repress warnings when int and
longs or int and shorts are the same type) LCC has this kind of
frontend/backend coupling.
A more difficult problem is that you want the compiler to provide a
warning based on the (constant) value of a shift count etc. Then you
would have to model the >> and check for values 8..15, 16..31 etc to
calculate the number of bytes needed for the result. However for more
general a >> c types of constructs the gain will be minimal.
This type of code is often used for more low level programming. Why
not let the programmer state to the compiler that he knows that the
results fits in a short: s = (unsigned short)(u >> 16);
Just like you suppress unused paramer warnings with
(void)a;
Regards,
Rinie
Return to the
comp.compilers page.
Search the
comp.compilers archives again.