lwip-users
[Top][All Lists]
Advanced

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

Re: R: [lwip-users] struct ip_addr VS struct in_addr


From: Jonathan Larmour
Subject: Re: R: [lwip-users] struct ip_addr VS struct in_addr
Date: Fri, 29 Aug 2008 15:10:56 +0100
User-agent: Thunderbird 1.5.0.12 (X11/20070530)

Ceresoli Luca wrote:
> Jonathan Larmour wrote:
>> dst_in_addr will already be aligned, so does not need memcpy. You can
>> just do: dst_ip_addr.addr = dst_in_addr->addr;
>> 
>> However in the other direction - if there's an ip_addr you need to
>> convert back to a struct in_addr, then you /would/ need memcpy, to
>> safely guarantee alignment.
> 
> Thanks for the reply Jonathan.
> 
> It's not clear to me why one direction would need memcpy() and not the
> other. (I am speaking in general, not about the example function I
> provided)

One of them will be assumed by the compiler to be already aligned, the
other one wouldn't. If you assign something aligned to something which the
compiler thinks may not be aligned it will still work. The opposite is not
the case.

> Anyway, for the records, it turns out that even though my CPU (Blackfin)
> does not support unaligned access, the compiler (from Analog Devices)
> will translate those accesses into 4 byte accesses. It will be slow and
> pointer-unsafe, but so far it's ok for my --very limited-- case.

I doubt it does it all the time on all structures! It presumably only does
that if it knows that the structure is packed - I assume that there is a
way to do this on your compiler.

Jifl
-- 
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------       Opinions==mine




reply via email to

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