Question

I have some legacy code that I am trying to improve... one approach I like to take is using structures to organize data rather than equivalence operations.... shudder. This is on OpenVMS Fortran 6.4 which I understand to be Fortran77 plus some stuff (might be wrong).

I want to initialize a record variable like so:

structure /my_data/
  integer*2   var1
  integer*2   var2
  character*5 NameTag
end structure

record /my_data/ OrganizedData

data OrganizedData /1, 2, 'Fred '/

I know the data statement is an error, the compiler told me so. Checking in the help files, it appears that DATA does not support record variables in this version. Can anyone confirm? Any suggestions to initialize something like this other than direct assignments?

Était-ce utile?

La solution

I have only the Oracle (Sun) manual here, not from OpenVMS, but it implements the same VAX extension (completely non-standard!). There is no structure constructor described there, that you could use for creating values of structure in single expression.

It also says:

Record fields are not allowed in COMMON statements.

Records and record fields are not allowed in DATA,EQUIVALENCE, or NAMELISTstatements.

Record fields are not allowed in SAVE statement.

If you can use a compiler which accepts Fortran 90 you could use

type my_data
  integer*2   var1
  integer*2   var2
  character*5 NameTag
end type

type(my_data) :: OrganizedData

OrganizedData  = my_data(1, 2, 'Fred')

(I left the also non-standard * notation there.)

Autres conseils

This is how you do it in DEC Fortran:

structure /my_data/
  integer*2   var1 /1/
  integer*2   var2 /2/
  character*5 NameTag /'Fred'/
end structure

record /my_data/ OrganizedData

end

Note that the initializations are on the type - this will give the same initial values for all variables of that type.

For that version of DEC FORTRAN, if you want different values for each instance, I think you need to initialize the record fields at run time.

 OrganizedData.var1 = 1 ! etc.

There are tricks, like using a COMMON and making a MACRO Assembler PSECT that initializes the values at compile time, but I'm guessing that's not what you are looking for. (Let me know if you are).

Also, I forget if it's 6.4 or not, but receiving a passed argument that has static initialization would cause a compiler error or warning.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top