你好,我最近调试项目时发现如下这种情况:
我在一个c文件里定义了两个全局变量,unsigned int num; 和 unsigned int date[]; 。调试时发现num分配的地址是0x118000d4;date数组分配的首地址是0x118000d0。结果是当date数组有很多数据存放时,就会把num的值给覆盖了,不知道应该怎样才能避免这种情况发生呢?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
你好,我最近调试项目时发现如下这种情况:
我在一个c文件里定义了两个全局变量,unsigned int num; 和 unsigned int date[]; 。调试时发现num分配的地址是0x118000d4;date数组分配的首地址是0x118000d0。结果是当date数组有很多数据存放时,就会把num的值给覆盖了,不知道应该怎样才能避免这种情况发生呢?
可以用#pragma DATA_SECTION ( symbol , " section name ")把数组定义到一个专门的段,然后这个段要预留足够的空间给数组。