Okay to declare static global variable in .h file?

后端 未结 6 1996
野趣味
野趣味 2020-12-13 07:36

static keyword keeps the scope of a global variable limited to that translation unit. If I use static int x in a .h file and include that .h file every

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 08:04

    Basically, each source file together with all included header files is a single translation unit. So If you have a static variable in a header file then it will be unique in each source file (translation unit) the header file is included in.

提交回复
热议问题