Struct as return value from a function?
Hello I'm totally new to C and trying to translate a matlab program to C.
The question I have is if it's ok to return a struct from a function. I know I should be using pointers but haven't really gotten the hang of it yet, and as i understand you don't have to use them but for speed purposes you should?
Anyways here is some code that I wonder if it's ok to use in C.
Code:
typedef struct results {
double F_TT_out;
double F_PP_out;
double F_GG_out;
double F_HH_out;
double F_SS_out;
double F_EE_out;
double Tout;
} results;
results the_under(results output_r);
results the_over(results output_c);
results the_process(//here there will be inputs){
results output_c;
results output_r;
values are assigned to output_r...
double n_iter = 0;
double E = 100; /* Error */
double last_temp_out = 10000 /* assigned value, will store the temp from previous iteration */
while (E>0.0001){
n_iter=n_iter+1;
if(n_iter==????){
break;
}
output_c = the_under(output_r);
output_r = the_over(output_c);
E = fabs(last_temp_out-output_r.Tout);
last_temp_out = output_r.Tout;
}
return //some struct
}
results the_under(results output_r){
results under;
Calculations that assign values to the struct results under...
return under;
}
results the_over(results output_r){
results over;
Calculations that assign values to the struct results over...
return over;
}
Is this way of coding an ok way?
Thank you so much for any answers!