Re: Implemenation Indepdent Way to Move LSByte of Char to MSB of Int, etc

From: Eric Sosman (esosman_at_acm-dot-org.invalid)
Date: 01/17/05


Date: Mon, 17 Jan 2005 16:49:01 -0500

bd wrote:
> Eric Sosman wrote:
> [...]
>> Maybe there's a way to calculate (UINT_MAX + 1)/(UCHAR_MAX + 1)
>>without risking zero in the numerator and/or denominator, but I
>>haven't figured one out. (Note that UCHAR_MAX == ULLONG_MAX is
>>permitted by the Standard.)
>
> Since UCHAR_MAX <= UINT_MAX <= ULLONG_MAX...
>
> #if UCHAR_MAX == ULLONG_MAX
> # define UINT_UCHAR_RATIO 1
> #else
> # define UINT_UCHAR_RATIO \
> (((unsigned long long)UINT_MAX + 1) / \
> ((unsigned long long)UCHAR_MAX + 1))
> #endif

     If UINT_MAX == ULLONG_MAX, this yields a ratio
of zero.

-- 
Eric Sosman
esosman@acm-dot-org.invalid