Checking addresses of fortran passed variables in a c func
Posted on 2003-12-01
I'm having some trouble with some fortran code. Arithmetic exception at the return from a subroutine. This only occurs with optimization; if I turn on debugging it works fine. I've checked everything I possibly can, but I don't see anything wrong. It could be something farther up the line is awry.
I suspect that memory is a bit screwed up. The code is too big to have the cross reference checker available on the sun do this for me. It bombs at the end, complaining of too many files or something like that.
I thought I would write a generic c function that would check the addresses of passed variables before a call, and then call it again once inside the routine, via some sort of c function. I could place this at points in the code which I suspect are giving me problems.
I don't know if this is possible in fortran, but I don't think so. So I'm looking to c.
Since fortran always passes by reference, or address, and c will allow me access to the address of the pointer, it seems the way to go.
What I've done so far is copied the signature of the fortran subroutine call into a call to a c routine, declared the integer variables as int *'s, real variables as float *'s, and double precision variables as double *'s. Then I store the addresses of the variables (first element in array case) in a long int on the c side. But they all have the same value?! What am I doing wrong? For instance, here is one line which is supposed to store an address:
i1 = (long int*) rtest;
i1 is declared as long int, and in this particular case rtest is coming from fortran declared as real, and declared as float* on the c side.
If I print out the i1's, they all have the same value.
What stupid thing am I doing wrong here?
I've also tried it without the cast - no luck.
Once I have this going, I'm wondering if there's a more robust way of doing this. Something that would work regardless of the number of variables being passes...
Thanks very much!