I have some programming experience but not much with C.
I have a reasonably large C file. In it there are multiple functions that are executed sequentially - so in this particular case no function is called twice really, they are broken down for ease of reading, since each function still has a separate purpose.
This program does a lot of computations on several long arrays of double with variable length, so they are all pointers. Two questions:
1) The variables that are calculated once from the beginning and then serve as input to many subsequent functions - should I make them global variables inside this file? From my experience programming in higher level languages, global variables are not good. Is this not the case for C and why?
2) When 1 of my function wants to return multiple pointers (each points to an double array of length n for example), say double *p1, double *p2, double *p3 that are related, I can combine them into a struct:
struct pointers {
double *p1, *p2, *p3;
} ptr;
foo1 will take double *input as input, and calculate ptr->p1, ptr->p2, ptr->p3, and then ptr will later serve as input for foo2. Should I write
struct pointers *foo(double *input)
or
void foo1(double *input, struct pointers ptr)
or
void foo1(double *input, struct pointers *ptr)
Why is it that C functions are usually 'void' functions, unless it returns just an int or double variables? Having input and output both as parameters - is it confusing?
Should I initialize ptr->p1, ptr->p2, ptr->p3 inside or outside of foo1?
Note that foo() is the main function that will call foo1, foo2 sequentially.