global data

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

global data

933 次查看
bones
Contributor I

I am using the MC9S12Xeq512 processor as a new user. I had a problem when a c file had a global variable of type struct is declared. The program built ok using Cosmic but the app did not run. I changed the global to static const and all was well. The funny thing is that the global was only used by functions inside the file. Any ideas for this behavior. With this paged memory, are there rules of thumb for treating global and file scope variables?

 

Thanks,

David 

标签 (1)
0 项奖励
回复
1 回复

767 次查看
Lundin
Senior Contributor IV

I don't know Cosmic, but it seems that the problem could be related to static initialization. If you declare a variable as const it will likely end up in flash, and if ou don't declare it as const, it will likely end up in RAM. And then, if you pick a minimal non-standard startup code as is custom with most embedded compilers, the variable won't be initialized and contain garbage values.

0 项奖励
回复