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

can constants defined in a file be used in other file without defining ?

i have defined

#define key0  0x35 
in main file and now i want to use key0 in one of included file in this project
but on compilation i get error for this.
Does keil have any provision where i can use defined constants
of one file in other file without redefining them ?

Parents
  • Arjun asked:
    > doubt!! --> KEYS_H_HDR
    > (#ifndef KEYS_H_HDR
    > #define KEYS_H_HDR )
    > Does this should be same as header file > name ?

    The label name is arbitrary, but it keeps things neat to make it the same as the header filename.
    This is a very common technique to avoid "multiple definition" errors if the same header file is referred to twice. (The first reference will "define" KEYS_H_HDR, so a second reference will "comment out" the entire contents of the header file.

    If your C textbook does not refer to header files, then get another one. This is a fundamental part of the C language.

Reply
  • Arjun asked:
    > doubt!! --> KEYS_H_HDR
    > (#ifndef KEYS_H_HDR
    > #define KEYS_H_HDR )
    > Does this should be same as header file > name ?

    The label name is arbitrary, but it keeps things neat to make it the same as the header filename.
    This is a very common technique to avoid "multiple definition" errors if the same header file is referred to twice. (The first reference will "define" KEYS_H_HDR, so a second reference will "comment out" the entire contents of the header file.

    If your C textbook does not refer to header files, then get another one. This is a fundamental part of the C language.

Children
No data