[ECOS] Network programming for eCos under linux
Mark Salter
msalter@redhat.com
Wed Aug 8 09:04:00 GMT 2001
>>>>> Trenton D Adams writes:
>>
>> > 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!
> 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?
How about this (assuming you need integer alignment):
int aligned_buffer[1024/sizeof(int)];
char *buffer = (char *)&aligned_buffer;
--Mark
More information about the Ecos-discuss
mailing list