I'm creating a header only library and I wanted to check if the user has defined <string.h> so that I can use memcpy. I read online about how libraries like stdio have guard macros, but I couldn't find one for string.h. Any ideas? Or is there a way just to see if memcpy is a function?
You can portably tell if string.h
has not been included.
Per 7.24.1 String function conventions, paragraph 1 of the (draft) C11 standard:
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 issize_t
and the macro isNULL
...
If NULL
is not defined, then the user could not have included string.h
prior to including your header(s).
I see no portable way of definitively determining if string.h
has been included.