Search code examples
c++cstandard-librarylinkage

Are all functions in the c++ standard library required have external linkage?


So I've got an app which compiles fine on windows, linux and a few variations of unix. I recently decided to port it to OSX when I ran into a snag.

I have a template which looks like this:

template<int (&F)(int)>
int safe_ctype(unsigned char c) { return F(c); }

the idea being to prevent sign extension from crashing certain implementations when given input values above 0x7f. It is typically used like this:

safe_ctype<std::isspace>(ch);

This unfortunately doesn't work on OSX (using gcc 4.2). The error has to do with std::isspace not having external linkage and therefore not applicable for templates. It turns out that on OSX, the ctype.h header has all functions (through macros) marked static inline.

Here's my question:

Is it permitted by any relevant standard for functions in the C++ (in this case the parts inherited from C's) standard library to not have external linkage?

EDIT:

I've heard back from apple. Apparently they have a macro to control this behavior. Defining _DONT_USE_CTYPE_INLINE_ prevents the ctype functions from being static inline.


Solution

  • C++03 §17.4.2.2/1 says:

    Entities in the C++ Standard Library have external linkage.

    The same is true in C: C99 §7.1.2/6 says:

    Any declaration of a library function shall have external linkage.