inline specifier
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
[编辑] 语法
inline function_declaration | |||||||||
[编辑] 说明
inline关键字是一个提示给编译器进行优化。编译器将忽略此请求的自由.
原文:
The inline keyword is a hint given to the compiler to perform an optimization. The compiler has the freedom to ignore this request.
如果编译器内联的功能,它取代了每次调用该函数与实际的身体,而不会产生通话.
原文:
If the compiler inlines the function, it replaces every call of that function with the actual body (without generating a call).
这避免了额外的开销创建的堆栈上放置数据和检索结果的函数调用(),但它可能会导致一个更大的可执行代码的功能有被重复多次.
原文:
This avoids extra overhead created by the function call (placing data on stack and retrieving the result) but it may result in a larger executable as the code for the function has to be repeated multiple times.
结果是到函数宏类似
在当前转换单元,函数体必须是可见的.
原文:
The function body must be visible in the current translation unit.
类体里面定义的类的方法被隐式声明为inline..
原文:
Class methods defined inside the class body are implicitly declared inline.
[编辑] 示例
inline int sum(int a, int b) { return (a + b); } int c = sum(1, 4); // if the compiler inlines the function the compiled code will be the same as writing int c = 1 + 4;