Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!unmvax!brainerd From: brainerd@unmvax.unm.edu (Walt Brainerd) Newsgroups: comp.lang.fortran Subject: Re: Pointer examples and 8x Message-ID: <194@unmvax.unm.edu> Date: 30 Jun 89 23:20:07 GMT References: <661hallidayd@yvax.byu.edu> Organization: University of New Mexico at Albuquerque Lines: 48 In article <661hallidayd@yvax.byu.edu>, hallidayd@yvax.byu.edu writes: > Chris Torek (chris@mimsy.UUCP), see if the following function is not a > direct port of your C code (message <18236@mimsy.UUCP>, with corrections > given in message <18265@mimsy.UUCP>) to Fortran 8x. > > TYPE (NODE), POINTER FUNCTION INSERT (HEAD, NEWNODE) ! I believe this to ^^^^^^^^^ Can't put this on function line (irregularity?) > ! be proper syntax > ! for such a FUNCTION > > TYPE (NODE), POINTER :: HEAD, NEWNODE > TYPE (NODE), POINTER :: PTR > INTEGER :: NUMBER = NEWNODE % VALUE ! I believe the syntax ^^^^^^^ , DATA ^^^^^^^ Until recently, it was proposed that you could do this with a DATA attribute; now use the old DATA statement. > ! allows the initial- > ! ization to involve > ! the arguments in > ! this way. > ! (It should.) > > PTR => HEAD > DO, WHILE (ASSOCIATED (PTR % NEXT) .AND. PTR % NEXT % VALUE < NUMBER) > ! This (and the C code) work > ! because the .AND. operator > ! is a "short circuit" form. ^^^^^^^^^^^^^^^^^^^^^^^^^ > ! (See Ada for a language that > ! distinguishes between short > ! circuiting and non-short > ! circuiting logical operators.) Nope! Fortran says things can be evaluated in any order, so this will not (necessarily) work if PTR % NEXT is not ASSOCIATED. > PTR => PTR % NEXT > END DO > NEWNODE % NEXT => PTR % NEXT . . . This person obviously has gotten the hang of the new pointers. Glad to see others giving these things a shot to see how they work. Walt Brainerd Unicomp, Inc. brainerd@unmvax.cs.unm.edu -- Walt Brainerd Unicomp, Inc. brainerd@unmvax.cs.unm.edu