[英]How is a header only ANSI C library possible?
There is a very popular library named nuklear that is both written in ANSI C and entirely header only. 有一个非常受欢迎的名为nuklear的库, 它既是用ANSI C编写的,也完全是标头的。 However, there can only be one definition of functions in each translation unit, and ANSI C does not have inline
functions, so how does this library work properly without linker errors? 但是,每个转换单元中只能有一个函数定义,并且ANSI C没有inline
函数,那么该库如何正常工作而没有链接器错误?
Starting at line 73 is a description on how to use this header: 从第73行开始,描述了如何使用此标头:
/// ## Usage
/// This library is self contained in one single header file and can be used either
/// in header only mode or in implementation mode. The header only mode is used
/// by default when included and allows including this header in other headers
/// and does not contain the actual implementation. <br /><br />
///
/// The implementation mode requires to define the preprocessor macro
/// NK_IMPLEMENTATION in *one* .c/.cpp file before #includeing this file, e.g.:
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C
/// #define NK_IMPLEMENTATION
/// #include "nuklear.h"
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So normally including this header file will only give you the declarations. 因此,通常包括该头文件只会给您声明。 If you #define NK_IMPLEMENTATION
before including, then the implementation is included. 如果在包含之前#define NK_IMPLEMENTATION
,则包含实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.