Hi there,
How could one easily force alignment of variables in code (avoiding creation of specific section in linker files, and explicit placement via OBJECT)? Something similar to the #pragma pack present in other micros.
Thanks.
----------------------------------
Hola,
¿Cómo se puede fozar fácilmente la alineación de variables desde el código (evitando crear secciones nuevas en el fichero del linker y evitando tener que colocar cada variable con OBJECT)? Algo parecido a #pragma pack existente para otros micros.
Gracias.
Solved! Go to Solution.
Hi Carlos
Good news. I found out that one of our customers is doing exactly what you need.
The "trick" he used is adding attribute to variable definition. For example:
char test[6] __attribute__((aligned(2)));
I did not try it yet.
If someone of CW staff watching this place, please comment. I saw no CW documentation for using attributes in code, only for LCF
I hope it helps
I think that the ALIGN command will do what you need. See ALIGN and ALIGNALL in the ELF linker file issue.
Hi Ben,
thanks for your answer.
However, as far as I know, ALIGN is for the linker file, not for the code (*.c) file. I´m looking for a more flexible way that doesn´t imply changing linker file.
Best regards,
Hi Carlos
Good news. I found out that one of our customers is doing exactly what you need.
The "trick" he used is adding attribute to variable definition. For example:
char test[6] __attribute__((aligned(2)));
I did not try it yet.
If someone of CW staff watching this place, please comment. I saw no CW documentation for using attributes in code, only for LCF
I hope it helps
Hi Ben,
thank you for the info. I´ve found that from CW10.6 on it´s possible to do __attribute__((aligned(2))), though it seems that __attribute__((aligned(1))) is not working.
Regards
Hi Carios
Thats correct, but you can add once to the linker file a section with ALIGNALL definition, and in the code putting the variables you want to align in this section.
The problem I have with the alignment is that you can not align data to 1 byte long, the minimum is 2 bytes. in data communication I need 1 byte too