Mail Archives: djgpp/1997/01/13/11:13:09
At 10:43 13/01/97 +0000, Leendert Combee wrote:
>> 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 !!
>
> Leendert
>
Do you have test cases to support evidence on this? The pointer passed as
parameter in the function is _a copy_ of the pointer sent as argument, so
Casteel's comments seem correct, except if the C compiler you use afterwards
in the generated code decides to "optimize" so much to use the same memory
position!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cesar Scarpini Rabak E-mail: csrabak AT ipt DOT br
DME/ASC Phone: 55-11-268-3522 Ext.350
IPT - Instituto de Pesquisas Tecnologicas Fax: 55-11-268-5996
Av. Prof. Almeida Prado, 532. Sao Paulo - SP 05508-901 BRAZIL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Raw text -