Getting warnings for long to short assignments (how)? 
Author Message
 Getting warnings for long to short assignments (how)?

We had a program which was assigning a long to a short and, not surprisingly,
broke in a big way when running.  What I was surprised about was that there
were no warning messages, and there didn't seem to be any way to get the
compiler (gcc 2.5.8/SunOS 4.1.3) to give any!  I realise lint has an option
for this but we have ANSI programs and a non ANSI lint (SunOS) and they just
don't mix.

I wouldn't expect K&R C to complain but why doesn't ANSI (or is it just gcc)?
K&R II (p. 42) state "Expressions that might lose information, like assigning a
longer integer type to a shorter, [...], may draw a warning, but they are not
illegal."  Fair enough, so why doesn't gcc warn me?  It was a very {*filter*}
problem for us.

Is there some way to get a warning message?  

What's the rationale behind the current behaviour?


Prentice Centre  
University of Queensland    4072
AUSTRALIA --   Phone: +61 7 365 3610

Mon, 21 Oct 1996 13:08:38 GMT  
 Getting warnings for long to short assignments (how)?


>What's the rationale behind the current behaviour?

Its very common to assign from a longer to a shorter int type (e.g. from an
int to a char) so generally its not desirable to issue warnings for this.
Of course a compiler is quite free to implement such warnings and if you
feel your compiler is lacking in this respect you should tell the compiler
producer. It is not however a standards issue.



Wed, 23 Oct 1996 02:38:02 GMT  
 [ 2 post ] 

 Relevant Pages 

1. short/long/long long Formatting questions

2. warning: ambiguous assignment: assignment op taken

3. 32-bit shorts (was a long long title)

4. char size (was long long long long long int)

5. Unexpected warning on _variant_t to bool assignment

6. C4244 warnings ULONG_PTR to DBBYTELENGTH assignment

7. Warning: Assignment of read-only member?

8. warning: possibly incorrect assignment

9. Pointer assignment warnings

10. Compiler warning for assignment in if statement?

11. warning on using += with a short VC7.0

12. BUG ? : warning C4706: assignment within conditional expression


Powered by phpBB® Forum Software