[Top][All Lists]
[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, 24 Aug 2011 15:45:47 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 |
Stephane Lesage wrote:
> Mason wrote:
>
>> src/include/lwip/def.h defines LWIP_U32_DIFF
>> a macro which used to compute the difference between two
>> u32_t values, taking wrap-around into account.
>> [...]
>> Therefore LWIP_U32_DIFF reduces to
>> #define LWIP_U32_DIFF(a, b) ((a)-(b))
>> I suggest removing the macro altogether, and applying the
>> following patch.
>
> This is what I also do in my sys_arch layer and programs.
I don't understand what you do in the sys_arch layer.
If you define LWIP_U32_DIFF in sys_arch.h or cc.h
then you will get a redefinition error, won't you?
> With 2's complement arithmetic you can just subtract.
> I checked it.
AFAIU, the method for signed number representation
(sign-and-magnitude, 1's complement, 2's complement)
has no bearing on unsigned arithmetic.
In C, it is guaranteed that unsigned arithmetic is
carried out modulo 2^N.
> But you need to make sure that both operands are the same size.
The macro doesn't check. We lose nothing if it is removed.
Right now, it is only used in one place, and it is used
with "matching" operands.
> Should we keep the macro for clarity ?
IIUC, the macro's purpose is similar to C99's difftime?
--
Regards.