[dpdk-dev] [PATCH] eal, power: don't use '-' sign with unsigned literals

Morten Brørup mb at smartsharesystems.com
Sat Mar 13 10:05:59 CET 2021


> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Tyler Retzlaff
> Sent: Friday, March 12, 2021 7:40 PM
> 
> On Fri, Mar 12, 2021 at 10:36:15AM -0800, Tyler Retzlaff wrote:
> > On Fri, Mar 12, 2021 at 05:37:41PM +0000, Bruce Richardson wrote:
> > > On Fri, Mar 12, 2021 at 09:05:58AM -0800, Tyler Retzlaff wrote:
> > > > > Not sure i agree. It's a very common pattern and is widely used and
> > > > > understood. I mean, if anything, seeing `~0` would have me stop and
> > > > > think as i've literally never seen such code before.
> > > >
> > > > it produces warnings under some compilers. in some enterprises we are
> > > > required to fix certain classes of warnings (not suppress them from
> the
> > > > command line) as a function of security policies.
> > > >
> > > > as an alternative would you be more willing to accept something like
> the
> > > > following? ``(unsigned long long)-1LL'' if you don't like ``~0ULL''
> it
> > > > would make explicit what the compiler is already doing.
> > > >
> > > > the issue is the application of the sign to what is clearly something
> not
> > > > signed; it get's flagged. so the cast is an explicit expression of
> intent
> > > > that will not generate the warnings.
> > > >
> > > > appreciate you're help in finding a solution even if it isn't the
> > > > proposed solution.
> > > >
> > > What about using ULLONG_MAX and similar defines from limits.h?

The type of the variable being manipulated is not unsigned long long, but uint64_t, which theoretically is not the same. Long long can be more than 64 bit, although all current implementations use 64 bit for long long.

So -1ULL was wrong from the start, and ~0ULL is similarly incorrect. The correct value would be UINT64_MAX from stdint.h.

> >
> > i think this would be okay even in circumstances where the code is
> > building masks so long as in practice it results in "all bits being
> > set". i'm not aware of a XXX_MAX where max isn't all bits set.. is
> > there?
> 
> just a qualification to my previous.
> 
> specifically for the UXXX_MAX (unsigned) preprocessor definitions, we
> aren't talking about signed here (or at least i wasn't).



More information about the dev mailing list