NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: toolchain/53618: bogus warnings from printf %u and ntohs with -O1



The following reply was made to PR toolchain/53618; it has been noted by GNATS.

From: Valery Ushakov <uwe%stderr.spb.ru@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: toolchain/53618: bogus warnings from printf %u and ntohs with -O1
Date: Sat, 22 Sep 2018 01:12:47 +0300

 On Fri, Sep 21, 2018 at 20:35:01 +0000, Robert Elz wrote:
 
 > From: Robert Elz <kre%munnari.OZ.AU@localhost>
 > To: gnats-bugs%NetBSD.org@localhost
 > Cc: 
 > Subject: Re: toolchain/53618: bogus warnings from printf %u and ntohs with -O1
 > Date: Sat, 22 Sep 2018 03:33:35 +0700
 > 
 >      Date:        Fri, 21 Sep 2018 11:20:01 +0000 (UTC)
 >      From:        Valery Ushakov <uwe%stderr.spb.ru@localhost>
 >      Message-ID:  <20180921112001.6B4C07A1D2%mollari.NetBSD.org@localhost>
 >  
 >    |  Isn't that what the 'h' length modifier (i.e. "%hu") is for?
 >  
 >  No, 'h' truncates the int value provided to 16 bits, it doesn't
 >  prevent the value being promoted from short to int in the first
 >  place.
 
 Right, and the standard even says that explicitly:
 
   h            Specifies that a following d, i, o, u, x, or  X
                conversion  specifier applies to a short int or
                unsigned short int argument (the argument  will
                have  been  promoted  according  to the integer
                promotions, but its value shall be converted to
                short   int   or   unsigned  short  int  before
                printing);
 
 >  And yes, all of this is bizarre, and gcc could be lots
 >  smarter about (almost all of) these kinds of warnings ....
 
 Yeah.  I'm a bit too tired so I can't think of a situation where using
 'h' with unsigned short would affect the result.  But my point was
 that %hu seems technically the right thing to do and it does shut up
 gcc.
 
 -uwe
 


Home | Main Index | Thread Index | Old Index