Reputation: 1457
I have multidimensional array
double coeff[10][3][12][519][11];
and I set the values for this array in a include-file ( #include "call_of_functions.h"
) in another function:
#include <stdio.h>
void func_T5_D1(double s, double t, double mt, double coeff[10][3][12][519][11])
{
#include "call_of_functions.h"
}
and I call this function in main.c
int main(){
double s, t, mt;
double coeff[10][3][12][519][11]={0};
double ex;
printf("enter 3 values for s, t and mt:\n");
scanf("%lf %lf %lf", &s, &t, &mt);
printf("%lf %lf %lf\n", s, t, mt);
func_T5_D1( s, t, mt, coeff);
ex = coeff[5][1][10][309][10];
printf("%.14e \n",ex);
return 0;
}
However I get a segmentation fault. If I include the #include "call_of_functions.h"
in main.c, it works well.
Upvotes: 1
Views: 189
Reputation: 16888
10*3*12*519*11* sizeof(double) is likely 16441920 bytes, which may be greater than the available stack space.
You may make the array global or allocate it dynamically.
Also note that the array is not passed by value to the function, only its address, so you have no problems with "returning the array" as you seem to think.
PS. As for the dynamic allocation, in your case you may do:
double (*coeff)[3][12][519][11];
coeff = calloc (1, 10 * sizeof (*coeff));
and don't forget to free
it.
Upvotes: 4