Compiler strange behavior with variable that use the "const" modifier.

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

Compiler strange behavior with variable that use the "const" modifier.

1,665 次查看
Claude_Sylvain
Contributor I
Hello,
 
I am using CodeWarrior V6.4 on Windows XP professionnal, on a project that use the MCF52223 MCU, and I have noticed a strange behavior of the compiler.
 
Below the explanation...
 
When defining an array like the following one:
 
/* +++ */
 
const unsigned char my_array[] = {0x01, 0x02, 0x03, 0x04, 0x05};
 
/* +++ */
 
This array is put in the .rodata section, and that's just what anybody expect.
 
But, when defining the save array with all value as 0x00, like the following:
 
/* +++ */
 
const unsigned char my_array[] = {0x00, 0x00, 0x00, 0x00, 0x00};
 
/* +++ */
 
The array is put in the .bss section !?!?
 
Why?
 
Is it a bug, or some strange feature that I do not understand ?
 
Claude.
Electro-Technica inc.
 
 
 
标签 (1)
标记 (1)
0 项奖励
回复
2 回复数

483 次查看
CrasyCat
Specialist III
Hello
 
THere is already another thread around that topic.
 
You need to use the pragma explicit_zero_data on
 
Please look at following thread for more details:
 
CrasyCat
0 项奖励
回复

483 次查看
Claude_Sylvain
Contributor I
Thank you.
 
Claude
Electro-Technica inc.
 
0 项奖励
回复