Silverfrost Forums

Welcome to our forums

UNION issue? Compiler issue?

9 Nov 2018 9:21 #22773

I was playing around with the UNION statement in a TYPE and ran into a run-time error that baffled me. When I do these declarations (code below), then do an I/O, it crashes with this error.

Error 90, File access and properties are incompatible

Best I can determine, this is proper usage in Fortran 95. Your insights will be useful.

    type:: abcdefg
    sequence
        union
            integer*2 dcba
            integer*2 qrst
            integer*4 uvwx
        end union
    end type
     type (abcdefg):: defg
     defg%uvwx = 32
     write(*,*)'this is a test'
    end
10 Nov 2018 1:17 #22774

UNION is an (obsolete) non-standard extension to Fortran 77, and not needed in Fortran 95.

The following code runs, but I am not sure what you wanted to do.

    program OBSOLETE
    implicit none
    type:: abcdefg
        sequence
        union
           map
              integer*2 dcba
              integer*2 qrst
           end map
           map
              integer*4 uvwx
           end map
        end union
    end type
    type (abcdefg):: defg
!
    defg%uvwx = 32 + 65536*16
    write(*,*)'this is a test: '
    write(*,10)'uvwx',defg%uvwx
    write(*,10)'dcba',defg%dcba
    write(*,10)'qrst',defg%qrst
 10 format(A4,2x,Z8)
    end
10 Nov 2018 2:41 #22775

mecej4, yes, there is something about using the MAP directive that makes the code work. This is an obsolete feature, yet it can have great utility. I have seen different implementations described; some require the use of the MAP directive, some do not.

Thanks for looking in to it deeper for me. It is appreciated.

Bill

10 Nov 2018 3:24 (Edited: 10 Nov 2018 11:54) #22776

MAP...END MAP is something that I could not find a proper description of in the FTN95 documentation. I ended up consulting the Digital/Compaq Visual Fortran Language Reference Manual, http://jp.xlsoft.com/documents/intel/cvf/cvf_lref.pdf .

My guess is that FTN95 supports correct usage of MAP...END MAP, but a program that uses it improperly or leaves out essential syntax will behave in an unpredictable manner when compiled with FTN95.

Out of curiosity, I tried Lahey Fortran 95 7.10 on your original code, and received the following useful error messages:

jwd1600i-s 'su0.f90', line 1: No component defined in derived type definition for 'abcdefg'. jwd1423i-s 'su0.f90', line 4: Only MAP declaration can appear in range of UNION declaration. jwd1423i-s 'su0.f90', line 5: Only MAP declaration can appear in range of UNION declaration. jwd1423i-s 'su0.f90', line 6: Only MAP declaration can appear in range of UNION declaration. jwd1497i-s 'su0.f90', line 10, column 11: 'uvwx' not a component of a derived type, cannot be specified as structure component.

As we can see, Lahey F95 can be useful in getting the syntax correct in your code, following which you can return to FTN95.

Another finding, worth appreciating, perhaps: your example as well as my modification embed a non-standard F77 extended type component (UNION) inside an F90 Derived Type, and it works!

10 Nov 2018 10:54 #22778

UNIONs, eh?

https://www.youtube.com/watch?v=69O8xmIeenU

Eddie

Please login to reply.