"Martin Wells" <(E-Mail Removed)> a écrit dans le message de news:

(E-Mail Removed) om...

> james:

>

>> if (UINT_MAX-6 == x ) ...

>>

>> Replace UINT_MAX with UCHAR_MAX, USHRT_MAX, ULONG_MAX, ULLONG_MAX, or

>> SIZE_MAX, as appropriate

>

>

> Using TYPE_MAX is no more universal than (TYPE)-1. I'm looking for

> something I can use with any unsigned integer type.
Here is one:

#define MWELLS_CMP(val, x) \

(((unsigned long long)(long long)(val) & \

(-1ULL >> ((sizeof(1ULL) - sizeof(x)) * CHAR_BIT)) == (x))

Use it as:

if (MWELLS_CMP(-6, x)) ...

It should work for any x with unsigned type.

Both val and x are evaluated once in the macro expansion.

A smart compiler should generate efficient code for types smaller than

unsigned long long, but it might not.

--

Chqrlie.