- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Hello,
I know that this is very basic question which is not only relating to Nios. In the web and in the documentation of GCC I didn’t find a satisfactory answer. Will a structure like the following always be aligned to the 4 byte boundary or do I have to tell the compiler the behaviour explicitly? The alignment is very important for dealing with the data by pointers. struct TEthernetHeader { u8_t dest[6]; u8_t src[6]; u16_t type; }; Regards, niosIIuserСсылка скопирована
6 Ответы
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
There is an article on embedded's website that describes what you want: Sizing and aligning device registers.
http://www.embedded.com/showarticle.jhtml?...cleid=160502362 (http://www.embedded.com/showarticle.jhtml?articleid=160502362)- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Hi,
Our experience is that on NIOS II structs always get aligned to 4 bytes. With kind regards, JMastron- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
You cannot rely on that. Compilers can and do align things as they see fit, and this could change in future revisions of the compiler. You need to look in the GCC documenation for the aligned attribute.
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Hello,
So something like the following will force the compiler that the structure will begin within a 4 byte boundary. Is that correct? struct __attribute__ ((aligned (4))) TEthernetHeader { u8_t dest[6]; u8_t src[6]; u16_t type; }; Regards, niosIIuser- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
niosIIuser,
From memory that looks correct, but you can be sure by aligning to a one or two-byte boundary and then examining memory of your struct in the debugger while altering the contents of its members as you step through the code. There is probably a much more elegant way of verifying this for the toolchain experts but the above will get the job done.- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Hello guys,
Thank you very much for your contribution. The posted information helped me a lot. Regards, niosIIuser
Ответить
Параметры темы
- Подписка на RSS-канал
- Отметить тему как новую
- Отметить тему как прочитанную
- Выполнить отслеживание данной Тема для текущего пользователя
- Закладка
- Подписаться
- Страница в формате печати