I’ve finished a project that relies heavily on string manipulation in C. The problem is that should I change my global variables to pass by reference instead? Code is longer than 300 lines, and the global variables seem to be doing fine. I’ve read other posts that pbr can increase readability.
I have about 6 global vars.
You should always aim to keep your state as small as reasonably possible. Having big state (roughly: at any point in the code, the number of accessible (dependable) variables is high) means more more responsibility at each point, more difficult maintenance, less intuitive to read.
So yes, global variables only where you can’t bear passing them to every little function.
If you have a throw-away program, global state is obviously ok, but then you normally don’t start in C in the first place.
6 global vars doesn’t sound much, but you can’t generalize.