有没有办法在 .c 文件而不是 .h 文件中定义 C 内联函数?
据我所知,C内联函数体应该在.h文件中定义 因为如果在 .c 文件中定义了函数体,它会导致错误“函数名已使用但从未定义”。
这是常规方法吗?或者如何在 .c 文件中定义内联函数体?
As I know, C inline function body should be defined in .h file
because it causes an error 'function-name used but never defined" if body defined in .c file.
Is this the regular way? Or how to define inline function body in .c file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个
.c
文件都独立编译为.o
输出。如果在.c
文件中定义内联函数,其他源文件就看不到该函数,从而无法内联。因此,内联函数应该位于
.h
文件中,以允许代码共享。Each
.c
file is compiled independently into.o
output. If you define the inline function in a.c
file, other source files cannot see such function, so that cannot be inlined.Therefore the inline function should be in the
.h
file to allow the code to be shared.