测试如下,定义两个变量,程序中都没有被使用到。其中一个是数组。为了避免被优化,都使用了__attribute__((used))进行修饰。
![]()
编译之后,在.map文件中,搜索这两个变量分配到的存储空间,结果只找到MyVariable_1这个变量,定义的MyVariable_0[10]数组,没有找到,可见还是被编译器优化掉了。

请问这种问题有没有解决方法?
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.
测试如下,定义两个变量,程序中都没有被使用到。其中一个是数组。为了避免被优化,都使用了__attribute__((used))进行修饰。
![]()
编译之后,在.map文件中,搜索这两个变量分配到的存储空间,结果只找到MyVariable_1这个变量,定义的MyVariable_0[10]数组,没有找到,可见还是被编译器优化掉了。

请问这种问题有没有解决方法?