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.

关于6416DSP代码优化问题

在主程序开头定义的循环变量例如

void main()

{  int i,j;

i=10;

}

如果不打开-o3优化,i是能正常赋值的,如果打开后,i就不能赋值了,好像被优化掉了,请问怎么才可以不被优化掉,谢谢

  • 用volatile定义一下。
  • 非常感谢您的建议,用了您的建议上面的问题解决了,可是我又遇到了类似的问题,我的一段程序代码也被优化掉了,代码如下:
    while(1)
    {
    if (Mcbsp0_flag == 1)
    {

    Mcbsp0_flag = 0 ;
    *(unsigned volatile int *)McBSP0_DXR = Send_to_master_buffer[j];
    j++;

    }
    if(j >= send_num)
    {break;}
    }
    这段代码就是通过McBSP0发送send_num个数据,当数据发送完成后跳出死循环,Mcbsp0_flag 标志是在发送中断服务子程序中置位的。