簡體   English   中英

僅標頭的ANSI C庫怎么可能?

[英]How is a header only ANSI C library possible?

有一個非常受歡迎的名為nuklear的庫, 它既是用ANSI C編寫的,也完全是標頭的。 但是,每個轉換單元中只能有一個函數定義,並且ANSI C沒有inline函數,那么該庫如何正常工作而沒有鏈接器錯誤?

從第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"
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

因此,通常包括該頭文件只會給您聲明。 如果在包含之前#define NK_IMPLEMENTATION ,則包含實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM