- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
- Using Nios-II with eclipse. While accessing integer(32 bit) form non word align location getting incorrect value as described in below example.
- Tested with eclipse version 13 and 16, both are giving same result. - Test case : -------------------------------------------------------------------------------- char c[10] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; printf("int = 0x%08x", *(int*)(&c[2])); -------------------------------------------------------------------------------- above code should print "int = 0x66554433" but getting "int = 0x44332211"Link copiado
4 Respostas
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
This is not due to Eclipse, it is a limitation of the Nios II architecture that does not support unaligned accesses.
But anyway, please note that using an unaligned pointer accesses is "undefined behaviour" in the C standard, so your code could return anything and still be 100% correct according to the C standard. This kind of construct is not portable because it can work on some architectures and not on others. It could even work on some compilers and not others.- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Daixiwen,
Thanks for you feedback. But we are porting LUFA USB host/device stack on nios-II. In it there is requirement of unaligned memory access from stack itself. Also we have checked many compilers for different platforms like NXP LPC microcontrollers, AVR (from Atmel) microcontrollers, windows, linux etc. But with all we are getting expected result. Thanks, Vasu.- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
I'm afraid you will have to go through the LUFA code and change all the places where unaligned pointers are used. To help you, you can use the -Wcast-align option in gcc and it will generate a warning each time it thinks an unaligned transfer can happen.
IIRC unaligned transfers trigger a bus error on some ARM architectures also so it's really not good practise when making portable code. GCC for ARM has a -mno-unaligned-access option that will automatically convert unaligned accesses into multiple byte accesses, but unfortunately it doesn't seem that this option is available for the Nios II architecture.- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hi Vasu,
Are you using "little Indian" or "big Indian "? please send a sample of the wrong and expected results to investigate.

Responder
Opções do tópico
- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora