Force variables alignment in MC56F8XXXX DSC

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Force variables alignment in MC56F8XXXX DSC

跳至解决方案
3,288 次查看
cabl
Contributor III

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.

标签 (1)
1 解答
2,907 次查看
Ben
Senior Contributor I

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

在原帖中查看解决方案

0 项奖励
回复
5 回复数
2,907 次查看
Ben
Senior Contributor I

I think that the ALIGN command will do what you need. See ALIGN and ALIGNALL in the ELF linker file issue.

2,907 次查看
cabl
Contributor III

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,

0 项奖励
回复
2,908 次查看
Ben
Senior Contributor I

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

0 项奖励
回复
2,907 次查看
cabl
Contributor III

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

0 项奖励
回复
2,907 次查看
Ben
Senior Contributor I

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

0 项奖励
回复