内联函数向前声明

编程入门 行业动态 更新时间:2024-10-25 19:34:07
本文介绍了内联函数向前声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

内联函数向前声明

本文发布于:2023-11-14 03:04:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586041.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内联   函数   声明

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!