Using the same variable in different files (using extern)

This question already has an answer here:

  • What is the effect of extern “C” in C++? 12 answers

  • The extern keyword should be placed in the header file, and the variable definition need only be in one source file, so what you want is this:

    In Ah:

    extern uchar *const x;
    extern uchar *const y;
    

    In Ac

    uchar *const x;
    uchar *const y;
    

    In Bc

    #include "A.h" 
    
    void someFunction() {
        foo(x);
        bar(y);
    }
    

    In Cc

    #include "A.h"
    
    void someOtherFunction() {
        foo(x);
        bar(y);   
    }
    
    链接地址: http://www.djcxy.com/p/40494.html

    上一篇: 链接器错误与链接器无关

    下一篇: 在不同的文件中使用相同的变量(使用extern)