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.

全局变量初始化问题



hi TIer

    我现在的工作环境是startware,启动模式为uart,通过uart加载了boot代码后,再通过uart加载应用程序。   

应用程序如下:

#include<stdio.h>

static volatile unsigned int debug_num = 0x00;

void main()

{

    UARTPuts("\r\n debug_num:", -1);
    UARTPutHexNum((unsigned int)(debug_num));
    UARTPuts("\r\n", -1);

}

出现一个比较奇怪的问题,串口输出的debug_num值并不为初始化的值,而是一个随机值(每次加载值都是有变化的)

大家可以测试一下。请问一下这是GCC的编译选项设置产生的问题还是什么其他的原因。

BTW:内存肯定是没有问题的,在代码中任何位置对debug_num赋值都是正确的。