Search code examples
cmacrosc-preprocessor

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


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?


Solution

  • 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 is size_t and the macro is NULL ...

    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.