向前声明内联函数 [英] Forward declaration of inline functions

查看:180
本文介绍了向前声明内联函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个头文件,将包含大量(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>.

这篇关于向前声明内联函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆