lwip-devel
[Top][All Lists]
Advanced

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

Re: [lwip-devel] Bug in Checksum implementation and ARP fix


From: Atte Kojo
Subject: Re: [lwip-devel] Bug in Checksum implementation and ARP fix
Date: Thu, 30 Oct 2003 08:34:52 +0200

On Fri, 2003-10-24 at 08:47, Kenneth Porter wrote:
> performed masking to 8 bits. The DSP's word size was a fixed 32 bits (ie. you
> couldn't address anything less than that) so the compiler defined chars,
> shorts, and longs as 32 bits, and casting to char was a no-op.

There is another problem when using architectures like this (which seem
common in DSPs). I am working on a port for a 24-bit DSP which also has
fixed word size (all data types shorter that int are 24 bits) and the
biggest problem arises when casting void pointers (i.e. packet payload)
to structure pointers (headers, for example). 

The current code makes an assumption that casting a void * to u16_t *
packs two addresses into one. When sizeof(u8_t) == sizeof(u16_t) this
assumption is clearly invalid and struct members point to wrong
addresses.

My solution to this is to define all struct members as u8_t arrays and
use macros that pack/unpack the desired values to and from 16/32 bits.

> So make your assumptions about word sizes (and buffer packing) explicit,
> either by using macros for conversions, or by heavy use of comments.

I suggest macros. Comments are helpful but don't solve the actual problem
(which must then be solved individually by each user).

-- 
Thus spake the master programmer: "Though a program be but three lines
long, someday it will have to be maintained." 
-- Geoffrey James, "The Tao of Programming"





reply via email to

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