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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1,415 Views
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.
 
 
 
Labels (1)
0 Kudos
2 Replies

233 Views
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 Kudos

233 Views
Claude_Sylvain
Contributor I
Thank you.
 
Claude
Electro-Technica inc.
 
0 Kudos