Raffaele Borrelli wrote:
>
> Hello,
> until now I have used fortran77, but now I'm trying to
> work with fortran90.
> As a beginners with this standard I have some difficulties on
> understanding the real nature of the pointers.
> In C a pointer refer to the memory address af a varibale. So you have
> two operators & and *, the first assign to a variable (the pointer) the
> address and the second gives access to the value referred to by the
> pointers. If I have undestand well, in fortran 90 the pointers don't
> work in this way. If I write X => Y this is a sort of 'symbolic link',
> so that I can use X instead of Y. What is the difference, if any,
> between the two situations?
> May be they are the same but I haven't the notions to understand it.
>
> --
> Signed,
>
> Raffaele Borrelli
>
> e-mail: [log in to unmask]
Hi Raffaelle
Here are some important differences.
1) C provides "pointer arithmetic" so that memory address offset from a
pointer can be manipulated. Hence if
int * ptr;
int target[10];
ptr = ⌖
then all of these expressions refer to the value stored in element 3 in the
array target:
target[3]
*(ptr+3)
*(target+3)
Fortran 90 does not provide pointer arithmetic.
2) In C, because pointers are indexes into some memory space (possibly
virtual),
you can print out pointer values (i.e. addresses). In Fortran 90,
attempting to print out a pointer will print out the data aliased by that
pointer.
3) In C, you can set pointers to any value you like, (within OS determined
limits). So you could point at address 0x21486457 if you like. Or you can
point tot the address of any variable or array element. In Fortran 90,
pointers may only point at other pointers, or entities with the target
attribute. This is because in general aliasing inhibits optimisation.
4) In C, pointers of one type may be cast to pointers of another type. In
Fortran 90, this works sometimes (using Transfer), but this is unlikely to
be portable, and is rather unwieldy to implement in programs.
A symbolic link is a good way to describe F90 aliases.
Regards,
Andrej
--
!--------------------------------------------------------------------------!
! Dr Andrej Panjkov, Analyst/Programmer !
! Numerical Modelling Project, Coal Mine Engineering Group !
! CSIRO Division of Exploration and Mining !
! Queensland Centre for Advanced Technologies Tel: +61 7 3212 4693 !
! PO Box 883, Kenmore (Brisbane), Fax: +61 7 3212 4455 !
! Queensland, Australia, 4069 Mobile: 0417 551 435 !
!--------------------------------------------------------------------------!
! [log in to unmask] [log in to unmask] !
!--------------------------------------------------------------------------!
! This email is formatted for 76 character displays, using fixed fonts. !
!--------------------------------------------------------------------------!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|