Re: [PATCH] grep: remove tautological check
- From
Peter Krefting <peter@softwolves.pp.se>
- Date
- Oct 22, 2012, 13:20 UTC
- Message-ID
- <alpine.DEB.2.00.1210221416080.32103@ds9.cixit.se>
- In-Reply-To
- <1350753964-29346-1-git-send-email-dsp@php.net>
David Soria Parra:
> - if (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field) > + if (GREP_HEADER_FIELD_MAX <= p->field)
A friend taught me this trick, which will check that it isn't negative for compilers that have the enumeration be signed (notably MSVC), while not complaining for compilers that have it unsigned (GCC, Clang):
const unsigned int sign = 1u << (sizeof(p->field) * CHAR_BIT - 1); if (!(sign & (unsigned int) p->field) || GREP_HEADER_FIELD_MAX <= p->field)
-- \\// Peter - http://www.softwolves.pp.se/