This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Network programming for eCos under linux
- To: Jonathan Larmour <jlarmour at redhat dot com>
- Subject: [ECOS] Re: Network programming for eCos under linux
- From: "Grant Edwards" <grante at visi dot com>
- Date: Wed, 08 Aug 2001 16:19:12 GMT
- Cc: "Trenton D. Adams" <tadams at theone dot dnsalias dot com>,'Andrew Lunn' <andrew dot lunn at ascom dot ch>,'eCos discussion' <ecos-discuss at sources dot redhat dot com>
- References: <000001c12022$dfa2f460$090110ac@TRENT> <3B716392.17D4E08D@redhat.com>
Jonathan Larmour writes:
> "Trenton D. Adams" wrote:
>>
>> >
>> > > So, how would one go about making a buffer word aligned or DWORD
>> > aligned
>> > > just to be safe?
>> >
>> > something along the lines of:
>> >
>> > char buffer[1024];
>> > #define ALIGNMENT 8
>> > #define ALIGNUP(_x_) (((char *)(_x_) + ALIGN-1) & ~(ALIGN-1))
>> > int *foo = ALIGNUP(buffer);
>> >
>> > You could also use __alignof(int) to give the alignment but that's
>> > obviously a GNU C-ism.
>> >
>>
>> First of all, I assume your ALIGN is actually supposed to be ALIGNMENT!
>
> Oops yes.
>
>> I don't understand your macro. Let's say _x_ happens to be memory
>> address 0x201 the macro formula would go like this
>>
>> = (0x201 + 7) & ~(7)
>> = 0x208 & 0xfffffff8
>> = 0x208
>>
>> So, now foo is pointing to an integer that is not at the beginning of
>> the buffer. This would mean that I couldn't put anything at the
>> beginning of the buffer, correct?
>
> If 8 byte alignment was the requirement then you certainly wouldn't want
> to. I suppose in that case you would make the buffer be 1031 bytes to
> ensure it could fit 1024 bytes post alignment.
Yup -- but that only fixes the problem at the start of the buffer or
if you're using an array of homogeneously sized data objects.
If you're filling the buffer with a collection of packed, hetrogenous
data objects, you'll run into alignment problems somewhere else
in the buffer.
--
Grant Edwards
grante@visi.com