Why are global variables bad, in a single threaded, non-os, embedded application

后端 未结 13 1650
既然无缘
既然无缘 2020-12-01 05:20

Most of the objections I see to using global variables make sense since they refer to issues of multiple threads, thread safety, etc.

But in a small, single threaded

13条回答
  •  半阙折子戏
    2020-12-01 05:52

    The problem is tracking down which bit of your last code modified the state of the global. Generally, you want to keep variables within the smallest possible scope so that you can more easily reason about them.

提交回复
热议问题