Search code examples
cheaderinternalconventionproject-structure

C internal header conventions for libraries


Are there any conventions for seperating the public interface headers and internal headers? I've looked at some libraries and see that mostly the internal headers are in the src directory named something-internal.h and the public headers are in the include directory. I was thinking of something like this:

(xyz is the library name)

include/xyz/something.h (public interface)

struct something;
void do_something(struct something *s);

src/something.h (internal header)

/* include public header */
#include "xyz/something.h"

/* struct definition in internal header for opaque struct */
struct something { int x, int y };

src/something.c

/* not xyz/something.h, but the private header in src/ */
#include "something.h"

void do_something(struct something *s) {
        /* function definition */
}

So note that I don't use the -internal suffix, because in my opinion if the header is in the src directory it's internal. Is this clear enough for, for example, new contributors? Or should the -internal suffix be added for clarity?

`


Solution

  • I think what you suggest is perfectly fine. The linux kernel uses a similar layout with the public sched.h under include/ and the private sched.h under kernel/sched – Frederik Deweerdt