From: glynnec AT ix DOT netcom DOT com (Glynne Casteel) Newsgroups: comp.os.msdos.djgpp Subject: Re: f2c+djgpp Date: 12 Jan 1997 18:44:42 GMT Organization: Netcom Lines: 50 Message-ID: <5bbbeq$h8@dfw-ixnews12.ix.netcom.com> References: <9701121422 DOT AA18628 AT cambridge DOT scr DOT slb DOT com> NNTP-Posting-Host: den-co14-24.ix.netcom.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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 */ }