Calling C routine from F90, odd thing about numbers.

I’m calling a compiled C function from Fortran 90, and am getting results that don’t seem to make sense.

The function I’m calling takes in a couple integers and arrays of integers by reference and does computations based on them.

I’m finding that the C function is treating the numbers I send it differently depending on how I fill the array.

If I assign values to the array in such a manner:

do i = 1, 20
array(i) = i + 2
enddo

I get certain results, but if I assign any of the array elements explicitly as such:

array(5:5) = (/ 7 /)

I get different results from the C routine.
The numbers are the same, and the way I’m calling the C function are the same but the results are different and often more favorable.

What is even more confusing is that it doesn’t make any difference where in my code I include the explicit assignment. Even if it is only after the C function has already been called.

The C function was compiled with pgcc to avoid any possible cross compiler issues. I’ve also tried calling the function from another C program, which works without problems.

Does pgf90 treat variables differently in memory depending on how they are assigned values in code?

-vlad

Hi Vlad,

It’s probably not the assignment that causing the problem. Using an array constructor to initialize an array will cause the compiler to create an implied do loop.

I think I’d need to see the code to in order to determine why your getting different answers. Is it possible to send the code, or an working example which illustrates the issue, to trs@pgroup.com? Just ask them to pass the code along to me and I’ll see what I can find out.

Thanks,
Mat