关于inline内联函数

freefalcon 2004-07-22 11:16:47
gcc支持内联啊

但是我在test.h中定义一个inine函数后
然后在test1.c,test2.c中调用这个内联函数

结果gcc说函数重复定义,这样的语法在vc以及其它编译器中都是支持的啊(我现在在做移植),难道gcc下不能这样写?

那gcc下的内联函数应该怎样写啊?
...全文
106 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
沙沙的吹 2004-07-22
  • 打赏
  • 举报
回复
gcc是C嘛,不是c++啦,呵呵
freefalcon 2004-07-22
  • 打赏
  • 举报
回复
多谢pacman老兄,呵呵,还不如在C++版问你呢

为什么gcc这样做啊,C++标准可没有这样的规定
smaxll 2004-07-22
  • 打赏
  • 举报
回复
gcc当然支持了,贴代码看看
pacman2000 2004-07-22
  • 打赏
  • 举报
回复
inline函数得加上static。

-finline-functions
Integrate all simple functions into their callers.
The compiler heuristically decides which functions
are simple enough to be worth integrating in this
way.

If all calls to a given function are integrated,
and the function is declared static, then GCC nor-
mally does not output the function as assembler
code in its own right.

得是static的inline函数才有效。。。
GZ 2004-07-22
  • 打赏
  • 举报
回复
也是一样的,是不是头文件定义出了问题,把大概的程序贴出来让大家看看
pacman2000 2004-07-22
  • 打赏
  • 举报
回复
C++标准说,inline只是对编译器的一个建议,而且无法inline时需要当作普通函数处理而不是报错。很多编译器(好像是从Borland C++ DOS版就开始的)因为对一个函数判断是不是inline上很麻烦,还受调用方的影响,所以常常就按非inline处理了。

23,118

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧