Mail Archives: djgpp/1997/01/12/19:07:31
In <9701121422 DOT AA18628 AT cambridge DOT scr DOT slb DOT com> combee AT cambridge DOT scr DOT slb DOT com
(Leendert Combee) writes:
>
> Fortran example:
>
> subroutine test(a,n)
> integer n,i
> real a(n)
> do i = 1, n
> a(i) = ....
> end do
> return
> end
>
> This gets translated into a few lines of c-code, the crucial bit being:
>
> /* Parameter adjustments */
> --a;
>
> (the reason being that a[1] is now really the first element (index 0) of the
> original array). THE PROBLEM IS THAT POINTER a IS **NEVER** RESET: ++a
> So that if test is called twice, the pointer a is decreased *again*.
> I could not believe this when inspecting code, but I got suspicious when
> f2c+djgpp compiled code gave different results than f77 on unix.
>
> Anyone any comments?? Anyone with a more recent f2c willing to check
his/her
> code or the above simple example?
This is no cause for concern; a does not need to be reset! The reason
is that it is passed in as a pointer to the function. Something like
[I assume]:
void test( double *a, int n )
{
/* decrementing a here has no effect on its value
* in the calling program!!
*/
a--; /* calling program cannot see this */
/* HOWEVER changing the values that it points to
* will be reflected in the calling program
*/
a[1] = 16.0; /* calling program CAN see this change */
}
- Raw text -