有没有办法在 .c 文件而不是 .h 文件中定义 C 内联函数?

发布于 2024-08-31 04:45:33 字数 106 浏览 7 评论 0原文

据我所知,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年里的时光 2024-09-07 04:45:33

每个 .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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文