Unable to understand following function declaration

79 Views Asked by At

Can anybody explain following function declaration.

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

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On
inline uint64_t MY_FUNC(unsigned long param) __attribute__ ((pure, always_inline)); 
  • inline -- function declared inline, either as optimization hint or for linking purposes.
  • uint64_t -- fixed-width return type. Refer to <stdint.h>.
  • MY_FUNC -- function name
  • unsigned long -- type of parameter
  • param -- name of parameter
  • __attribute__ ((pure, always_inline)) -- GCC compiler-specific attributes. See ouah who ninja'd their description.

Voting to close as "too broad".