Use of static variables and functions in global scope

后端 未结 3 1278
半阙折子戏
半阙折子戏 2021-01-07 17:38

Is there a use for flagging a variable as static, when it lies in the global scope of a .cpp file, not in a function?

Can you use the static keyword for

3条回答
  •  独厮守ぢ
    2021-01-07 18:32

    In this case, keyword static means the function or variable can only be used by code in the same cpp file. The associated symbol will not be exported and won't be usable by other modules.

    This is good practice to avoid name clashing in big software when you know your global functions or variables are not needed in other modules.

提交回复
热议问题