When to use static keyword before global variables?

前端 未结 8 519
再見小時候
再見小時候 2020-11-28 20:12

Can someone explain when you\'re supposed to use the static keyword before global variables or constants defined in header files?

For example, lets say I have a head

8条回答
  •  借酒劲吻你
    2020-11-28 21:09

    Yes, use static

    Always use static in .c files unless you need to reference the object from a different .c module.

    Never use static in .h files, because you will create a different object every time it is included.

提交回复
热议问题