4 ms·
256.6K Non-Comment Lines C Source + 39.5K NCSL headers (Main CPU) Global variables in that kind of codebase might be -really- hard to keep track of how you are
by virtue3 4y ago
256.6K Non-Comment Lines C Source + 39.5K NCSL headers (Main CPU)
Global variables in that kind of codebase might be -really- hard to keep track of how you are accessing and writing them :/.
This gets really fucking nasty when you're doing things like setting it to volatile and potentially accessing it across threads and you end up with a partial write and then doing a read, etc.
I'm sure the axiom of "it's never tested as much as we want" still probably applies here and that's slightly terrifying.
also FTA:
2272 - global variable declared with different types
“Spaghetti code”:
Incomprehensible code due to unnecessary
coupling, jumps, gotos, or high complexity
Yeah that sounds fun. really fun. This is why I purposefully never work on any system that could kill someone. I just can't imagine being in charge of something like that and not wanting to go insane with knowing my code wasn't checked enough. or I wasn't careful enough.
- sidewndr46 4y agoIf you're declaring a variable as volatile and accessing it from separate threads, it is going to be "fucking nasty" in so many ways.
- jacquesm 4y agoIndeed, spaghetti code is bad, but spaghetti data manipulated by spaghetti code is orders of magnitude worse. The thing that I never got is why there are plenty of high level languages that have 'global' more or less as the default. This is asking for trouble. Side effects should be very carefully introduced and reasoned about and kept to an absolute minimum, not be the default sauce to sprinkle across your codebase, the possible number of states increases very rapidly if you do that.
- kevin_thibedeau 4y agoDynamic allocation is generally forbidden in this application so all system state has to be in global or static variables. Otherwise you'd have to invest in formal analysis tools to prove that memory won't be exhausted.
- monocasa 4y agoThe rumor I heard at the time was that large portions of the code were autogenned out of a Matlab model of the engine, and that was where the globals and awful code complexity metrics came from.
- stefan_ 4y agoYep. This is widespread practice in the industry and is arguably far superior to someone actually trying to model it all in C. It just looks weird in a disassembler because you end up with a million global variables and essentially no control flow. (It's specifically Matlab Simulink for those playing along at home)
- chillingeffect 4y agoIve exported several simulink models. Long functions, yes. Globals, no.
- monocasa 4y agoI've integrated several simulink models; they had an incredible amount of globals.
- 2143 4y ago> If you're trying to go around corners as fast as possible in a front-wheel drive car 1. Please don't do circus on public roads. 2. If you're on private roads, well, you know, front-wheel-drive cars tend to handle poorly in fast corners. Do yourself a favour and get a RWD or AWD or something.