有没有办法检查 <string.h> 是否包含在内?

Is there a way to check if <string.h> is included?

我正在创建一个仅 header 的库,我想检查用户是否定义了 以便我可以使用 memcpy。我在网上阅读了有关像 stdio 这样的库如何具有保护宏的信息,但我找不到 string.h。有任何想法吗?或者有没有办法只查看 memcpy 是否是一个函数?

您可以方便地判断 string.h 是否 未包含

根据(草案)C11 标准的 7.24.1 String function conventions, paragraph 1

The header <string.h> declares one type and several functions, and defines one macro useful for manipulating arrays of character type and other objects treated as arrays of character type. The type is size_t and the macro is NULL ...

如果 NULL 未定义 ,则用户无法在包含您的 header(s) 之前包含 string.h

我看不到明确确定 string.h 是否包含 的便携方法。

如果您需要<string.h>,请自行添加。您还可以转发声明 memcpy 并在不包含任何内容的情况下使用它:

void* memcpy( void *restrict dest, const void *restrict src, size_t count );