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

Tyler Retzlaff roretzla at linux.microsoft.com
Fri Mar 12 19:40:01 CET 2021


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?
> 
> 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