-3

任何人都可以解释以下函数声明。

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

2 回答 2

2

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.

于 2014-12-19T13:16:16.423 回答
0
inline uint64_t MY_FUNC(unsigned long param) __attribute__ ((pure, always_inline)); 
  • inline-- 内联声明的函数,作为优化提示或用于链接目的。
  • uint64_t-- 固定宽度的返回类型。请参阅<stdint.h>
  • MY_FUNC-- 函数名
  • unsigned long-- 参数类型
  • param-- 参数名称
  • __attribute__ ((pure, always_inline))-- GCC 编译器特定的属性。看看 ouah 忍者对他们的描述。

投票结束时“过于广泛”。

于 2014-12-19T13:18:15.260 回答