函数指针__attribute __((常量))的功能? [英] Function pointer to __attribute__((const)) function?
本文介绍了函数指针__attribute __((常量))的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何(在GCC /GNU C)你声明一个函数指针,它指向一个 __ __属性((常量))
功能?我希望编译器以避免产生通过函数指针调用的函数多次调用时,它可以缓存从previous调用的返回值的想法是。
解决方案
无效的typedef(* t_const_function)(无效)__attribute __((常量));静态__attribute __((常量))无效A(无效){
}静态无效B(无效){
}INT主(INT ARGC,为const char * argv的[]){
t_const_function A = A; //警告:初始化使合格
从不合格//函数指针:
t_const_function B =; 返回0;
}
或者只是:
__ __属性((常量))无效(*一)(无效)= A;
How (in GCC/"GNU C") do you declare a function pointer which points to an __attribute__((const))
function? The idea being that I want the compiler to avoid generating multiple calls to the function called through the function pointer when it can cache the return value from a previous call.
解决方案
typedef void (*t_const_function)(void) __attribute__((const));
static __attribute__((const)) void A(void) {
}
static void B(void) {
}
int main(int argc, const char* argv[]) {
t_const_function a = A;
// warning: initialization makes qualified
// function pointer from unqualified:
t_const_function b = B;
return 0;
}
Or just:
__attribute__((const)) void(*a)(void) = A;
这篇关于函数指针__attribute __((常量))的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文