C - wrapping globals in a struct?
It is well-known bad practice to have a "super header" file like "globals.h" or "includes.h" etc, because in addition to globals being bad in the first place, this also creates a tight coupling dependency between every single, unrelated file in your project.

Lets say you have a PWM driver and a RS-232 debug print module. You want to grab the RS-232 debug print module and re-use it in another project. Suddenly you find yourself needing some PWM.h which you haven't got a clue about what it is or where the need comes from. You'll find yourself asking why on earth you need a PWM driver to run RS-232.

And then we haven't even considered re-entrancy of this messy global struct. Lets not even do that.



The correct way to untangle global spaghetti would rather be something like this:


Is the variable used in the first place? If not, remove. (This is quite common)
Can the variable be moved to local scope inside a function?
Can the variable be moved to local .c file scope by making it static? Can you reduce access to it from outside the .c file by implementing setter/getter functions?


If all of the above failed, then the variable you find yourself looking at should either be a memory-mapped hardware register part of a register map, or it is some real-time critical dirty fix that was added during maintenance.