Gumley_LE@cc.curtin.edu.au (Liam Gumley) (01/10/91)
A VAX/VMS Fortran-77 question follows.... What I am trying to do is this.... Main program byte buffer(100) Subroutine (has 'buffer' passed to it) byte buffer(100) integer*4 data(20) equivalence ( buffer(3), data(1) ) The VAX compiler gives an error at the equivalence line. Now I know I could do the equivalence in the main program and pass 'data' to the subprogram, but I would like to do it in the subroutine if I can. Can I do this using structure and record statements, or some other way? Cheers, Liam. -- #Liam E. Gumley, Department of Applied Physics, Curtin University of Technology# #Perth, Western Australia. >>>All opinions expressed are exclusively mine.<<<#
ubiquity@cs.utexas.edu (Richard Hoffman) (01/10/91)
In article <6683.278c85d2@cc.curtin.edu.au> Gumley_LE@cc.curtin.edu.au (Liam Gumley) writes: >The VAX compiler gives an error at the equivalence line [when you try >to use EQUIVALENCE with a formal paramter]. Now I know I could >do the equivalence in the main program and pass 'data' to the subprogram, >but I would like to do it in the subroutine if I can. Can I do this using >structure and record statements, or some other way? I never have understood why you can't equivalence formal parameters, but most FORTRAN compilers won't let you. One workaround is to not pass buffer formally at all, but use labelled COMMON instead. For example: C Main program BYTE BUFFER(100) COMMON /X/ BUFFER C Subroutine INTEGER*4 DATA(20) COMMON /X/ DATA This may not be appropriate in all cases. -- Richard Hoffman IBM Entry Systems Division (512) 823-1822 1529 Ben Crenshaw Way Austin, TX 78746 "Life is a gamble at terrible odds; (512) 327-9232 if it were a bet you wouldn't take it" (Tom Stoppard)
burley@geech.ai.mit.edu (Craig Burley) (01/10/91)
In article <6683.278c85d2@cc.curtin.edu.au> Gumley_LE@cc.curtin.edu.au (Liam Gumley) writes:
Main program
byte buffer(100)
Subroutine (has 'buffer' passed to it)
byte buffer(100)
integer*4 data(20)
equivalence ( buffer(3), data(1) )
The VAX compiler gives an error at the equivalence line. Now I know I could
do the equivalence in the main program and pass 'data' to the subprogram,
but I would like to do it in the subroutine if I can. Can I do this using
structure and record statements, or some other way?
You can't equivalence dummies, as you have discovered. Instead, use
STRUCTURE, UNION, and MAP to make the same thing. I don't know if you'll
have to change the main program to pass the same data (STRUCTURE) type; I'd
guess not, since Fortran passes by reference anway and I don't think anything
about VMS' STRUCTURE facility requires passing additional information
(compare to CHARACTER type, which requires passing a length).
I don't have a VMS Fortran manual handy, but I'd guess what you need would
look something like this:
SUBROUTINE FOO(BUFFER)
STRUCTURE /BUFFERUNION/ BUFFER
UNION
MAP
BYTE BYTES(100)
END MAP
MAP
BYTE ignore(2)
INTEGER*4 DATA(20)
END MAP
END UNION
END STRUCTURE
Then you'd refer to BUFFER.BYTES or BUFFER.DATA. Good luck!
--
James Craig Burley, Software Craftsperson burley@ai.mit.edu