lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-devel] LWIP_U32_DIFF is unnecessarily complex


From: Mason
Subject: Re: [lwip-devel] LWIP_U32_DIFF is unnecessarily complex
Date: Wed, 23 Nov 2011 13:36:46 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110928 Firefox/7.0.1 SeaMonkey/2.4.1

Mike Kleshov wrote:

> Mason wrote:
> 
>> I think your question is equivalent to asking whether the
>> following statement is well-defined.
>>
>>  unsigned n = -42; /*** -42 has type int ***/
>>
>> 3.2 CONVERSIONS
>> 3.2.1.2 Signed and unsigned integers
> 
> No, it isn't.
> There is no type conversion involved in (a - b) where both a and b are u32_t.

Mike,

It is correct that the expression (a - b) has type unsigned int
if both 'a' and 'b' have type unsigned int (AFAIU).

The way I understand it, since the result of (a-b) may not fit in
an unsigned int, the value must be "reduced" to an unsigned int,
"reduced" being defined as "the non-negative remainder on division
by the number one greater than the largest unsigned number that can
be represented in the type with smaller size." (type with smaller
size being unsigned int in this case)

e.g. -42 = -1 x 4294967296 + 4294967254

quotient  = -1
remainder = 4294967254

I agree that there is room for confusion, and I looked for a
relevant Defect Report, but could not find one.

-- 
Regards.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]