很多函数只检查传递给它们的自变量,并且只影响返回值。 这是一个比 __attribute__((pure))
严格得多的类,因为不允许函数读取全局内存。
如果已知函数只能依靠其自变量起作用,则可以对其进行公共子表达式删除和循环优化。
此函数属性是 ARM 编译器支持的 GNU 编译器扩展。 它具有等效的关键字 __pure
。
int Function_Attributes_const_0(int b) __attribute__ ((const)); int Function_Attributes_const_2(int b) { int aLocal=0; aLocal += Function_Attributes_const_0(b); aLocal += Function_Attributes_const_0(b); return aLocal; }
在此代码中,只能调用一次 Function_Attributes_const_0
,并将结果加倍以获得正确的返回值。
编译器用户指南中的第 4-13 页的__pure。