Why would one use #include_next in a project?

It is used if you want to replace a default header with one of your own making, for example, let’s say you want to replace “stdlib.h”. You would create a file called stdlib.h in your project, and that would be included instead of the default header.

#include_next is used if you want to add some stuff to stdlib.h rather than replace it entirely. You create a new file called stdlib.h containing:

#include_next "stdlib.h"
int mystdlibfunc();

And the compiler will not include your stdlib.h again recursively, as would be the case with plain a #include, but rather continue in other directories for a file named “stdlib.h”.

Leave a Comment