向前声明内联函数

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

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

更多推荐

向前声明内联函数

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

发布评论

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

>www.elefans.com

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