Why would one use #include_next in a project?

后端 未结 3 970
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 13:07

To quote the iOS Documentation on Wrapper Headers:

#include_next does not distinguish between and \"file\" inclusion, nor do

3条回答
  •  青春惊慌失措
    2020-12-02 13:33

    include_next is used as a preprocessor directive to tell the compiler to exclude the search paths up to and including filename file.h from resolving to this header file. The typical need is when two header files of the same name need to be used. Use such features sparingly and only when absolutely necessary.

    For example:

    source file.c contents with the usual file.h from path 1:
    #include 
     int main() {
         printf("out value: %d", out_val);
         exit 0;
         }
    
    file.h header file in path 1 contents with file.h from path 2 included: include_next instructs that path 1 sub directory not be used as search path for file.h and instead use path 2 sub directory as search path. This way you can have 2 files of the same name without the fear of invoking a circular reference to itself.
    # include_next 
    int out_val = UINT_MAX - INT_MAX;
    
    file.h in path 2 contents
    #define INT_MAX 1<<63 - 1
    #define UINT_MAX 1<<64 - 1
    

提交回复
热议问题