From: Christoph Kukulies Message-Id: <199701131207.NAA06844@gilberto.physik.rwth-aachen.de> Subject: Re: f2c+djgpp In-Reply-To: <199701131043.KAA01153@tartan.scr.slb.com> from Leendert Combee at "Jan 13, 97 10:43:37 am" To: combee AT cambridge DOT scr DOT slb DOT com (Leendert Combee) Date: Mon, 13 Jan 1997 13:07:38 +0100 (MET) Cc: glynnec AT ix DOT netcom DOT com, djgpp AT delorie DOT com Reply-To: Christoph Kukulies MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit > > 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 */ > > > > } > > > > No!, on return a[i] correspond now to a[i+1] before the function was called > (+whatever happened in the function). Because a (not *a) is a pointer, > --a changes that value! The code generated by f2c shoudl really use > a_new-- = a ; and then work with a_new rather than a. This causes that > a[i] still points to same element of a before _and_after the function > call !! Sorry, you are wrong. As stated out earlier (and in the comment above), a pointer is passed on the stack to the function. Within the function anything can be done with this pointer. The stack is discarded when the function is exited and thus the value the pointer has in the calling program is unaffected. BTW, it is common 'technique' of f2c to decrement array pointers that way to be conformant with FORTRAN array numbering starting with 1 in contrary to C. > > Leendert > --Chris Christoph P. U. Kukulies kuku AT gil DOT physik DOT rwth-aachen DOT de