问题描述
我的 iPhone 应用程序遇到了烦人的问题.每当我将优化级别设置为无"以外的其他值时,都会出现计算错误.这只发生在为 iPhone SDK 构建时(iPhone 模拟器总是很好).
I'm having an annoying problem with my iPhone app. Whenever I set the optimization level to something other than "None", I get computation errors. This only happens in when building for the iPhone SDK (the iPhone Simulator is always fine).
我不介意在发布模式下禁用优化,但是当我这样做时应用程序有点太慢了.
I wouldn't mind disabling optimizations in release mode, but the application is a tiny bit too slow when I do that.
应用程序复杂,很难找到优化过度的部分.
The application is complex, so it is hard to locate the part that is too aggressively optimized.
我认为问题出在 GCC 方面,因为它似乎在优化 ARM 架构的代码方面存在问题.
I think that the problem is on the GCC side since it seems to have problem optimizing the code for the ARM architecture.
有没有办法只对代码的某些部分禁用优化?你会如何处理这种问题?
Is there a way to only disable optimizations only for certain part of the code? How would you deal with that kind of issue?
推荐答案
是的,这完全有可能.GCC 有一个属性:
Yes, that's entirely possible. GCC has an attribute for that:
/* disable optimization for this function */
void my_function(void) __attribute__((optimize(0)));
void my_function(void) {
/* ... */
}
将该函数的优化级别设置为 -O0
.您可以启用/禁用特定优化:
Sets the optimization level for that function to -O0
. You can enable/disable specific optimizations:
/* disable optimization for this function */
void my_function(void) __attribute__((optimize("no-inline-functions")));
void my_function(void) {
/* ... */
}
这篇关于如何处理编译器优化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!