我有一个头文件,将包含大量(30+)内联函数。
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.
单独函数的forward声明的语法是什么?
What is the syntax for a forward declaration of a stand-alone function?
{这适用于C99和C ++}
{This applies to C99 and C++}
FYI,我使用IAR Workbench C编译器设置为使用C99。
FYI, I am using IAR Workbench C compiler set to use C99.
推荐答案与非内联函数无异:
void func(); // "forward" declaration // ... inline void func() // definition { // impl }通常用于隐藏库用户定义的模式是将声明在一个头( ah )和第二个头中的定义( a_def.h ), code> #include 后者(为了简洁,省略了包含保护):
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):
// a.h void func(); #include "a_def.h" // a_def.h inline void func() { // impl }库用户只需 #include< a.h& code>。
The library consumer would simply #include <a.h>.
更多推荐
向前声明内联函数
发布评论