文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>都是内联函数惹的祸

都是内联函数惹的祸

时间:2007-04-23  来源:marsky

偶然发现MicaHWVerify的执行居然和gcc的优化选项-Os有关,在注释掉该选项时,SerialID可以进行读操作,但读出来的数据不对,为全ff,加上该选项之后则正常,分析其原因,应该是SerialID中使用了void inline TOSH_uwait(int u_sec),该函数为内联函数,在不使用优化选项时,该函数和普通函数一样,不在代码中进行替换,这样当大量重复使用时,由于ATmega128主频较低,函数调用又需要额外时间,所以导致精确的计时不再精确,产生偏差,最后SerialID也无法读到正确的数据。

gcc中关于inline function的描述

The following is a list of rules and characteristics having to do with function inlining:
■ No functions are actually expanded inline unless you use -O to specify some
level of optimization. It is done this way to simplify the use of a debugger.
A function can be forced to be expanded inline by assigning it the
always_inline attribute.
■ The result of declaring a function inline could make the code either larger or
smaller, depending on the size of the function, the complexity of setting up the
call frame, and the number of times the function is called.
■ Certain functions cannot be expanded inline. Among these are functions that
use a variable number of arguments, alloca, variable-size arrays, a non-local
goto, or a nested function. Problems also arise when a function is recursive or
there is a reference to its address. The command-line option -Winline will
issue a warning when a function declared as inline cannot be expanded inline.
■ In the ISO C program you can use the __inline__ keyword in place of the
inline keyword.
■ The -finline-functions command-line option can be used to instruct
the compiler to automatically select functions that are appropriate for being
expanded inline.
■ If an inline function is not declared as static, its body must also be generated
by the compiler because it could be called from another module. Declaring
a function as both inline and static will cause all occurrences of the function
to be expanded inline, and the code for the function itself is never generated.
The command-line option -fkeep-inline-functions will override this
behavior and cause the function body to always be created.
■ Defining a function in a header file as both extern and inline is almost the same
as declaring a macro. Another copy of the function, without extern and inline,
can be compiled and stored in a library so that non-inline references to it can
be resolved.
相关阅读 更多 +
排行榜 更多 +
风雷

风雷

角色扮演 下载
蜘蛛战士模拟

蜘蛛战士模拟

动作格斗 下载
仙栎日语

仙栎日语

学习教育 下载