Topic: short = short + short deserves warning from microsoft?


Author: shane@nugget.spr.com (Shane Hartman)
Date: 16 Apr 93 05:40:18
Raw View
Microsoft C++ gives a warning about conversion between different
integral types for expressions involving only shorts, e.g.

short a, b, c;

a = b + c;             // warning

Does the standard require this conversion?  Isn't this in fact wrong?
If not, was it the intent of the comittee to make us all type more
useless casts?  The intent of this expression is QUITE CLEAR.  I note
that cfront compilers do not give this warning.  Maybe I should chunk
this POS and start writing fortran instead.  Oh well, the ultimate
sledgehammer:

#define short int

So much for type safety...

K. Shane Hartman (shane@spr.com)
Director, R&D
Software Productivity Research, Inc.
1 New England Executive Park
Burlington, MA, USA 01803-5005
--
K. Shane Hartman (shane@spr.com)
Software Productivity Research, Inc.
1 New England Executive Park
Burlington, MA, USA 01803-5005




Author: erc@netcom.com (Eric Smith)
Date: Fri, 16 Apr 1993 21:14:40 GMT
Raw View
In article <SHANE.93Apr16054018@nugget.spr.com> shane@spr.com writes:
>
>Microsoft C++ gives a warning about conversion between different
>integral types for expressions involving only shorts, e.g.
>
>short a, b, c;
>
>a = b + c;             // warning
>
>Does the standard require this conversion?  Isn't this in fact wrong?
>If not, was it the intent of the comittee to make us all type more
>useless casts?  The intent of this expression is QUITE CLEAR.  I note
>that cfront compilers do not give this warning.  Maybe I should chunk
>this POS and start writing fortran instead.  Oh well, the ultimate
>sledgehammer:
>
>#define short int
>
>So much for type safety...

You can disable each warning with a pragma.  This is a very effective
and pragmatic solution to an annoying problem.





Author: shane@nugget.spr.com (Shane Hartman)
Date: 17 Apr 93 14:03:21
Raw View
In article <ercC5LHoG.Lou@netcom.com> erc@netcom.com (Eric Smith) writes:

   In article <SHANE.93Apr16054018@nugget.spr.com> shane@spr.com writes:
   >
   >Microsoft C++ gives a warning about conversion between different
   >integral types for expressions involving only shorts, e.g.
   >
   >short a, b, c;
   >
   >a = b + c;             // warning
   >

   ...

   You can disable each warning with a pragma.  This is a very effective
   and pragmatic solution to an annoying problem.

Yes, I know that I can do that in Microsoft C++ (not all warnings can
be disabled, but this one can).  The problem is that I want that
warning in other circumstances.  The real issue is the compiler right
or wrong for promoting an expression involving only shorts to int (it
is the promotion that causes the warning).
--
K. Shane Hartman (shane@spr.com)
Software Productivity Research, Inc.
1 New England Executive Park
Burlington, MA, USA 01803-5005




Author: jimad@microsoft.com (Jim Adcock)
Date: 19 Apr 93 23:04:30 GMT
Raw View
In article <SHANE.93Apr16054018@nugget.spr.com> shane@spr.com writes:
|
|Microsoft C++ gives a warning about conversion between different
|integral types for expressions involving only shorts, e.g.
|
|short a, b, c;
|
|a = b + c;             // warning
|
|Does the standard require this conversion?  Isn't this in fact wrong?
|If not, was it the intent of the comittee to make us all type more
|useless casts?  The intent of this expression is QUITE CLEAR.

In which case it is unfortunate that the various flavors of C implemented
over the years disagree as to the intent of the expression.  However,
since different flavors of C *have* disagreed about the intent of the
expression over the years, the Microsoft C/C++ compiler *will* warn
you if you use the statement -- but only if *you* tell the compiler that
*you* require the highest level of warnings be emitted.  If you don't
require that highest degree of warning about all kinds of possible things
in your code that could be considered wrong by one or another standard of
what is right or wrong, then please *don't* specify the highest level of
warnings from the compiler -- because such is intended to be the
"mother of all warnings levels"!  By this, I mean -W4 turns on *all* warnings
that anyone could possible want, such that if you don't want ALL these
warnings, you can then selectively turn some of them off using #pragmas.

As a simple example of why someone might want this warning, consider
someone wanting to write maximally portable code, code that has
identical meaning under ANSI C, K&R C, and C++.  Then, this warning
makes sense.

Note, if people could agree on what the warning messages should be,
then they wouldn't be warnings, they would be errors, defined by the
language.  Since people can and do disagree on what warning messages
*they* think the compiler should emit, the compiler supports 5 standard
levels of warning messages, plus allows *you* to select what warning
messages *you* like by using #pragmas.

In summary, I suggest that you and the vast majority of people ought
to be compiling at warning level -W3 or less.  Or use the provided
pragmas to set the warning message as *you* desire.