The function pointer to the __attribute __ ((const)) function?
source link: https://www.codesd.com/item/the-function-pointer-to-the-attribute-const-function.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
The function pointer to the __attribute __ ((const)) function?
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;
Related Articles
C - What is the advantage for the user of const in the parameters of the functions that are not pointers?
Why does C ++ allow, but ignore the application of const to types of functions?
What is the prototype & ldquo; Const int * foo (int) & rdquo; Means, especially in contrast with & ldquo; Int * foo (int) & rdquo; I understand the second only
CUDA How to access constant memory in the kernel of the device when constant memory is declared in the host code?
What is the difference between const int *, const int * const and int const *?
Why does std :: distance not work on the mix of const and non const const?
What is the definition of const-correctness?
What is the difference between const virtual and virtual const?
the qualitative adjustment (const / volatile) may cause ambiguity
The difference between const string & amp; and string & amp; without const
CLR: What is the lifetime of const string values in memory?
Why does NSCalendar have two init methods with similar parameter types that accept one of the calendar identifier constants?
What is the difference between const and readonly?
Why is the build-constructor const argument constant?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK