Force variables alignment in MC56F8XXXX DSC

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Force variables alignment in MC56F8XXXX DSC

ソリューションへジャンプ
3,291件の閲覧回数
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,910件の閲覧回数
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,910件の閲覧回数
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,910件の閲覧回数
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,911件の閲覧回数
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,910件の閲覧回数
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,910件の閲覧回数
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 件の賞賛
返信