分类: C/C++
2008-12-31 10:01:14
昨天阅了一段mips汇编代码,发现我的inline没如愿地被展开.一顿纳闷之后跟同事讨论,说inline是建议性的关键字,为确认准确性,在《C Reference Manual》中找到了答案,摘相关要点如下:
The inline
designation is only a hint to the translator, suggesting that calls to the
inline function should be as fast as possible. The name comes from a compiler
optimization called inline
expression.
…
There are
three important principles for inline expansion:
1.
Visible
definition. In C99, if a
function is declared inline, then the function’s definition must be visible in
that translation unit.
2.
Free
choice. Translators are never
obligated to perform inline expansion. A C program must never
depend on whether a call is expanded.
3.
Same
meaning. Inline
expansion is only an optimization; it does no change the meaning of the
program.
…
1 基础不扎实
2 有疑问时,多交流,并查阅权威进行确认