Declaring,initializing and using a global variable in same header file

前端 未结 2 1179
我在风中等你
我在风中等你 2021-01-19 12:54

I am actually trying to use a variable that is initialized in a header file(say x.h) and want to use same variable inside inlined code in the same header file. The same var

2条回答
  •  萌比男神i
    2021-01-19 13:14

    Using the extern reserved word.

    Never create variables in '.h' files, it's a bad practice that leads to bugs. Instead, declare them as extern everywhere you need to use them and declare the variable itself only in a single '.c' file where it will be instantiated, and linked to from all the other places you use it.

提交回复
热议问题