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

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

问题描述

我有一个要包含的内联函数大量(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.

什么为独立函数的前向声明的语法

What is the syntax for a forward declaration of a stand-alone function?

{这适用于C99和C ++}

仅供参考,我使用IAR工作台C编译器设置为使用C99。

FYI, I am using IAR Workbench C compiler set to use C99.

推荐答案

没有不同于非内联函数:

No differently than a non-inline function:

void func();       // "forward" declaration

// ...

inline void func() // definition
{
    // impl
}

通常使用的模式来隐藏从库消费者的定义是把声明在一个头文件(),并在第二个标题(定义 a_def.h ),则有原的#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方式>

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

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