Search code examples
clinuxfunctionlinux-device-drivergcc-extensions

Unable to understand following function declaration


Can anybody explain following function declaration.

inline uint64_t MY_FUNC(unsigned long param) __attribute__ ((pure, always_inline)); 

Solution

  • always_inline and pure are gcc function attributes. From gcc documentation:

    always_inline

    Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function independent of any restrictions that otherwise apply to inlining. Failure to inline such a function is diagnosed as an error. Note that if such a function is called indirectly the compiler may or may not inline it depending on optimization level and a failure to inline an indirect call may or may not be diagnosed.

    Your MY_FUNC function already has the inline function specifier but in C inline is only a suggestion to inline and the compiler has no obligation to inline the function.

    pure

    Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure.