M
Max
Warning: newbie question!
If I have a function (translated from fortran using f2c)
int fun1(integer *n, doublereal *x)
{
integer m, i;
m = (*n);
for(i = 0; i < m; i++)
x = 0.;
return 0;
}
where (from f2c.h)
typedef long int integer;
typedef double doublereal;
Then I use it in a C program written from scratch:
< all include files here>
int main()
{
int n = 5;
double *x = malloc(n * sizeof(doublereal));
int retval;
retval = fun1((integer &)n, x);
return 0;
}
I get segmentation fault on 64-bit architecture. The problem is that n
is not passed correctely to fun1, even with a cast. Defining in main()
integer n = 5
then it works. A more elegant solution?
Thanks
Max
If I have a function (translated from fortran using f2c)
int fun1(integer *n, doublereal *x)
{
integer m, i;
m = (*n);
for(i = 0; i < m; i++)
x = 0.;
return 0;
}
where (from f2c.h)
typedef long int integer;
typedef double doublereal;
Then I use it in a C program written from scratch:
< all include files here>
int main()
{
int n = 5;
double *x = malloc(n * sizeof(doublereal));
int retval;
retval = fun1((integer &)n, x);
return 0;
}
I get segmentation fault on 64-bit architecture. The problem is that n
is not passed correctely to fun1, even with a cast. Defining in main()
integer n = 5
then it works. A more elegant solution?
Thanks
Max