内联函数的前向声明
我有一个头文件,其中将包含大量(30+)内联函数。
我不想让读者滚动或搜索内联函数的定义(实现),而是希望有一个前向声明部分来声明函数声明以及描述该函数的注释。本节将允许读者了解如何使用函数或查找函数,而无需向下滚动到实现。
另外,我希望读者养成使用函数的习惯,而无需查看其实现。
独立函数的前向声明的语法是什么?
{这适用于 C99 和 C++}
仅供参考,我正在使用 IAR Workbench C 编译器设置为使用 C99。
I have a header file that is going to contain a large amount (30+) of inline functions.
Rather than having the reader scroll or search for the definition (implementation) of the inline function, I would like to have a forward declaration section that states the function declaration with comments describing the function. This section would allow the reader to find out how to use a function or to look for a function without having to scroll down to the implementation.
Also, I would like the readers to get in the habit of using functions without having to see their implementations.
What is the syntax for a forward declaration of a stand-alone function?
{This applies to C99 and C++}
FYI, I am using IAR Workbench C compiler set to use C99.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与非内联函数没有什么不同:
通常,用于向库使用者“隐藏”定义的模式是将声明放在一个标头 (
ah
) 中,并将定义放在第二个标头 (< code>a_def.h),然后让前者#include
后者(为简洁起见,省略了包含防护):库使用者只需
#include.
No differently than a non-inline function:
Typically the pattern used to "hide" the definitions from the library consumer is to put the declarations in one header (
a.h
) and the definitions in a second header (a_def.h
), then have the former#include
the latter (inclusion guards omitted for brevity):The library consumer would simply
#include <a.h>
.您不需要“转发声明”它(该术语通常仅适用于类型,因为我们通常在首先声明它们的同一位置定义它们)。
只需像平常一样声明它即可:
现场演示。
You don't need to "forward declare" it (a term that is usually only applied to types, since we usually define them in the same place that we first declare them).
Just declare it, like normal:
Live demo.
要同时使用 C++ 和 C99,请将声明也设为内联,如下所示:
To work with both C++ and C99, make the declaration inline too, like this: