I'm working on a project what is becoming more and more complicated. Project consists of independent from each other sections of code containing a lot of math computations followed by complicated output generation. All that is wrapped inside a socket with pthread.
Whole thing looks something like this:
Main() -> socket -> thread -> request processing -> one or more of the independent sections
I wanted to enclose each independent section of code inside a function, and for that function to inherit variables from a caller function, but that didn't work.
Below is simplified version of what I want to achieve:
void func_a(){int c;b+=a;c=1;b+=c;}
int main(){
int a,b,c;
a=3;b=2;c=0;
func_a();
printf("b:%d c:%d\n",b,c);
return 1;
}
Above code doesn't work, but this one works fine, and does what I want:
int main(){
int a,b,c;
a=3;b=2;c=0;
{int c;b+=a;c=1;b+=c;}
printf("b:%d c:%d\n",b,c);
return 1;
}
I could just put code for a function into a file, and then do { #include ... }, but perhaps there's a better way to do that?
Any other ideas and suggestions on managing such thing are appreciated too.
Thanks.
P.S.
Using global scope is not an option, because of threading. Just passing variables to a function is not an option, it will take 30+ arguments. I already have a bunch of struct's going on, so putting all variables into a single struct is not an option ether.