global constants without using #define

前端 未结 2 602
面向向阳花
面向向阳花 2021-02-07 14:04

Ok, I\'m looking to define a set of memory addresses as constants in a .h file that\'s used by a bunch of .c files (we\'re in C, not C++). I want to be able to see the name<

2条回答
  •  走了就别回头了
    2021-02-07 14:47

    Declare the constants in the header file using extern:

    extern const short int SOME_ADDRESS;
    

    then in any, but only one, .c file provide the definition:

    const short int SOME_ADDRESS = 0x0010;
    

提交回复
热议问题