×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

pointer to available datatype

pointer to available datatype

pointer to available datatype

(OP)
Hellow everybody,

I am wondering whether there would be a way in FORTRAN to get a pointer address to an available datatype.

For example:
I have the below data type

CODE

module dt
type data
integer, dimension(3) :: comp
real, dimension(:), pointer :: a => null
end type 
end module dt 
and I would create

CODE

program test
use dt
implicit none
type(data) :: mytype
end program test 

Now I am wondering defining mytype, is there anyway I can get a pointer address to this type.

Thanks a lot in advance.
Cheers,



RE: pointer to available datatype

What have you tried? Have you read up on Fortran 90 Pointers at all?

I am not even sure what your are asking; in fact, your question seems mis-constructed to me..."pointer address"? Did you mean to say "address pointer"?

To tell you the truth, I am yet to use pointers in Fortran; but, a bit of reading triggered by your post revealed that pointers and addresses are 2 different things and, apparently, Fortran (unlike C) tends to hide such inner-details from the programmer...this has been on purpose, by the way, and that is why it has been very difficult to produce memory-related problems in Fortran.

Getting back to your "pointer address":
Do you really need the address? or
Do you just need the ability to use pointers?

RE: pointer to available datatype

CODE --> fortran

module dt
  type data
    integer, dimension(3) :: comp
    real, dimension(:), pointer :: a => null() ! notice the difference with your version
  end type 
end module dt 

program test
  use dt
  implicit none
  type(data),target :: mytype
  type(data),pointer :: mytype2
  real, dimension(:), pointer :: vect
  mytype2=> mytype ! mytype2 becomes an alias of mytype
  allocate(vect(10)) ! usually, I only allocate allocatable objects but for you ...
  vect=5
  mytype2%a => vect
  write(*,*) mytype%a ! I hope 10 values equal to 5
end program test 

Fran├žois Jacq

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close