This may be a stupid question, sorry.
I've read about the drawbacks of global variables a lot on this site. I'm finally trying to increase my code quality for a large project that'll be reviewed by many. I understand that using global vars makes code harder to debug, since one doesn't know where the variable may be altered (making spaghetti code).
However, I've got a fairly specific case in which I can't really think of a way to avoid global variables. I have a program running on an embedded device (under FreeRTOS, all in C) in which I have about 20 reasonably complex functions, in which there are perhaps 10 global variables passed around. About 3/4 of the code is real-time, and the rest is asynchronous, using the variables the other functions manipulate and sending their contents to a server.
Here's a snippet of pseudocode:
float important_var = 0;
void some_synchronous_function(){
do_something();
math.operation(important_var);
}
void do_something(){
important_var+=5;
}
void async(){
if(important_var > 5){
//whatever
}
}
main(){
some_synchronous_function();
}
Is this a reasonable way to do this? (cowers in fear)