This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

.h file need include in two c source files

Hello,
I have two c source files in my project, and they both need include hardware.h(register define) file. I try to include the .h file to both C file but the compilter says the memory overlap. I choice include .h file to the main C file ,the compiliter says another c file's register not define.
How to avoid it ,
thanks a lot.

Parents
  • yeah,you are right
    We must put the definition into the c source files,and declare them in the header files.
    //my.h
    #ifndef __MY_H__
    #define __MY_H__

    extrn unsigned char xdata A_register _at_ 0x0010;
    extrn unsinged char xdata B_register _at_ 0x0020;//unnecessary if the variables are not global

    #endif //__MY_H__

    //My.c
    unsigned char xdata A_register _at_ 0x0010;
    unsinged char xdata B_register _at_ 0x0020;

    The include guard is necessary to avoid re-including.

Reply
  • yeah,you are right
    We must put the definition into the c source files,and declare them in the header files.
    //my.h
    #ifndef __MY_H__
    #define __MY_H__

    extrn unsigned char xdata A_register _at_ 0x0010;
    extrn unsinged char xdata B_register _at_ 0x0020;//unnecessary if the variables are not global

    #endif //__MY_H__

    //My.c
    unsigned char xdata A_register _at_ 0x0010;
    unsinged char xdata B_register _at_ 0x0020;

    The include guard is necessary to avoid re-including.

Children