Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > bogus warning?

Reply
Thread Tools

bogus warning?

 
 
Ian Collins
Guest
Posts: n/a
 
      10-14-2011
On 10/14/11 03:30 PM, Stefan Ram wrote:
> Ben Bacarisse<(E-Mail Removed)> writes:
>> What was your suggestion that the OP "read the prepositions carefully"
>> for?

>
> A warning about converting from int to short would be
> natural, since a narrowing conversion obviously might
> destroy information.
>
> A warning about a widening conversion from short to int
> would be strange. Since no information can be lost, there
> is no need for a warning in this case.
>
> Since the OP was wondering about the warning, he must have
> read the warning as a warning about a widening conversion.
> (There would be no reason to wonder about a warning about
> a narrowing conversion, since a warning would be normal
> in this case.)
>
> Since the warning was about a narrowing conversion, however,
> he must have misread the warning about a narrowing
> conversion as a warning about a widening conversion.
>
> Thus, he must have mistakenly read the »form« as a »to« and
> the »to« as a »from«.


That's a pretty big stretch when the OP wrote:

"But I thought operands only got promoted to the lowest type that
included all the operands."

That looks to me like he wasn't expecting any promotions. A perfectly
logical assumption.

--
Ian Collins
 
Reply With Quote
 
 
 
 
James Kuyper
Guest
Posts: n/a
 
      10-14-2011
On 10/13/2011 10:30 PM, Stefan Ram wrote:
....
> Since the OP was wondering about the warning, he must have
> read the warning as a warning about a widening conversion.
> (There would be no reason to wonder about a warning about
> a narrowing conversion, since a warning would be normal
> in this case.)


As I read his message, he was unaware that any conversion at all was
taking place, and would therefore have been equally surprised by any
message about any conversion, whether widening or shortening.
--
James Kuyper
 
Reply With Quote
 
 
 
 
steve
Guest
Posts: n/a
 
      10-14-2011
On Oct 13, 10:16*pm, James Kuyper <(E-Mail Removed)> wrote:
> On 10/13/2011 10:30 PM, Stefan Ram wrote:
> ...
>
> > * Since the OP was wondering about the warning, he must have
> > * read the warning as a warning about a widening conversion.
> > * (There would be no reason to wonder about a warning about
> > * a narrowing conversion, since a warning would be normal
> > * in this case.)

>
> As I read his message, he was unaware that any conversion at all was
> taking place, and would therefore have been equally surprised by any
> message about any conversion, whether widening or shortening.
> --
> James Kuyper


You are correct sir. I was surprised that there was any conversion at
all since both operands were 'short'. Never the less, apparently I am
getting senile since a search of the c.l.c archives show that I asked
a similar question question several years ago.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      10-14-2011
Ian Collins <(E-Mail Removed)> writes:
>That looks to me like he wasn't expecting any promotions. A perfectly
>logical assumption.


From steve's first reply I already learned that I erred with
my assumptions about steve's knowledge. Moreover, in the
meantime, I also have learned that I was wrong with my ideas
about the from-to-phrase-order. So, I was totally wrong by
all means.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-14-2011
http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram) writes:
> Ian Collins <(E-Mail Removed)> writes:
>>That looks to me like he wasn't expecting any promotions. A perfectly
>>logical assumption.

>
> From steve's first reply I already learned that I erred with
> my assumptions about steve's knowledge. Moreover, in the
> meantime, I also have learned that I was wrong with my ideas
> about the from-to-phrase-order. So, I was totally wrong by
> all means.


It happens to all of us.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      10-15-2011
"christian.bau" <(E-Mail Removed)> writes:

> On Oct 13, 10:16Ā*pm, Ben Bacarisse <(E-Mail Removed)> wrote:
>
>> Not at all. Ā*It's warning you that the conversion implied by the
>> assignment (do you see that the warning is about the conversion from int
>> back to short int?) might go wrong. Ā*If, for example, 'a' is more that
>> SHRT_MAX/2 then 'a + a' may be perfectly well defined, but the
>> conversion back to short int could go wrong.

>
> If short = 16 bits, and int = 16 bits, then the situation would be
> exactly the same, that is you will get a correct result for exactly
> the same values, and an incorrect result for exactly the same values.
> However, the conversion from int to short couldn't possibly fail. And
> the addition that fails would be an addition of ints. So should the
> compiler give a warning in that case?


The conversion can't go wrong so, no, there should be no warning.

In the situation you describe, it would be the undefined behaviour on
overflow that might be warned about; not the now safe conversion from
int to short. I doubt anyone would advocate warning about potential
overflow since there would be far too many "false positives".

Conversions from longer to shorter types are more rare, so a warning
about it might be considered helpful. Even so it's worth pointing out,
I think, that the warning in question has to be asked for. It is not
even included in -Wall or -Wextra.

--
Ben.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
NTP on a router picking up a bogus server John Caruso Cisco 5 11-26-2005 04:58 PM
bogus questions on PrepLogic Tina MCSD 3 10-11-2004 11:24 PM
Filtering bogus TCP packets David Cisco 5 06-03-2004 12:45 PM
firewalls "removing bogus header" Karl Seguin ASP .Net 4 02-10-2004 06:31 PM
This is such a bogus article George Hester ASP .Net 1 07-31-2003 12:37 PM



Advertisments