You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
-
Thanks for all your answers, I've changed the code, and it's good to know I don't need to change my practices too much :) (Global variables were banned in all the development environments I worked in in the 1990s) So am I right to conclude that I only NEED to use a global if I refer to it in setup() and loop()? Everything else can be local and passed around?minisaurus– minisaurus2018年12月20日 10:21:58 +00:00Commented Dec 20, 2018 at 10:21
-
1@minisaurus: Yes, that's right. However, now that he ban is lifted, I suggest you try to avoid thinking of globals as evil. If you find yourself passing a variable around through many functions, consider making it global: does that hurt the program's readability? If the answer is "no", then a global is probably a good choice.Edgar Bonet– Edgar Bonet2018年12月20日 10:32:44 +00:00Commented Dec 20, 2018 at 10:32
-
I'm out of touch, but is the ban really lifted in professional environments with several developers, APIs, libraries and who knows how many files of source code? But I can see how globals maybe aren't a big problem in these single file small Arduino projects.minisaurus– minisaurus2018年12月20日 13:50:03 +00:00Commented Dec 20, 2018 at 13:50
-
1@minisaurus: I don't know on these environments. My answer is specifically for the kind of programs you write on smallish embedded devices.Edgar Bonet– Edgar Bonet2018年12月20日 15:36:17 +00:00Commented Dec 20, 2018 at 15:36
lang-cpp