Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!mp.cs.niu.edu!ux1.cso.uiuc.edu!news.iastate.edu!IASTATE.EDU!keinert From: keinert@IASTATE.EDU (Keinert Fritz) Newsgroups: comp.lang.fortran Subject: Summary: pointers in Fortran Message-ID: <1991May17.115453@IASTATE.EDU> Date: 17 May 91 16:54:53 GMT Sender: news@news.iastate.edu (USENET News System) Reply-To: keinert@IASTATE.EDU (Keinert Fritz) Organization: Iowa State University Lines: 70 Thanks to all who replied to my question about pointers in Fortran. Our Internet connection was down for a couple of days, so e-mail was delayed, and this newsgroup has not been downloaded yet. I hope this posting makes it out, and does not duplicate too many other postings. According to the replies I got, pointers are documented in the Fortran for RISC Installation Guide, rather than the manual, and also in Sun, SGI and Cray Fortran. I found them in a Cray manual. I thought the declaration for a pointer to real was pointer (p,real) This is incorrect, or rather, it defines p as a pointer to a variable called "real". This is not what I intended. The correct notation is real r pointer (p,r) which defines a variable p of type "pointer to real". As far as calculating and printing goes, p is treated as an integer. There is no storage reserved for the variable r, even though it appears that way. Rather, r is the name that is given to the contents of p. In C notation, r would be called *p. There is a referencing operator loc(), but no dereferencing operator. Instead, the dereferenced version of a pointer has its own name. A fancy way to copy the value of y to x, in C: float x, y, *p; y = 3.; p = &y; x = *p; The same in Fortran: real x, y, r pointer (p, r) y = 3. p = loc(y) x = r This way of handling pointers is really clumsy. In C: float x[5], *p; for (p = x; p < x+5; p++) *p = 0.; becomes in Fortran real x(5), r pointer (p,r) p = loc(x(1)) do i = 1, 5 r = 0. p = p + 4 enddo The only good use I found for pointers in Fortran at the moment is dynamic memory allocation (see separate posting). -- Fritz Keinert phone: (515) 294-5128 Department of Mathematics fax: (515) 294-5454 Iowa State University e-mail: keinert@iastate.edu Ames, IA 50011