Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29236 Discussions

Compilation error when using Class(*), Intent (out)

Vasili_M_
Beginner
652 Views

Have written a routine to convert a character to integer

    Integer :: j
    Write (*,*) '# Call str_to_num ("12", j)'
    Call str_to_num ("12", j)
    Write (*,*) "j: ", j



I am using class(*) and getting error


    Program received signal 11 (SIGSEGV): Segmentation fault.


However when I change `Class(*)` with `Integer`, I do get
`" Subroutine str_to_num"` being printed.

Furthermore, changing to `Intent(inout)` rather than `Intent(out)` gets
the routine to work
 

    Subroutine str_to_num  &
    (                             &
     s, num, fmt, wrn            &
    )
 
    Character (len=*), Intent (in) :: s
    Character (len=*), Intent (in), Optional :: fmt

    Class (*), Intent (out) :: num
    Character (len=*), Intent (inout), Optional :: wrn

    Integer :: ios
    Character (len=65) :: frmt

    Write (*,*) " Subroutine str_to_num"
     Select Type (num)
       Type Is (Integer)
         Read (s, *, iostat=ios) num
       Type Is (Real)
         Read (s, *, iostat=ios) num
       Type Is (Double Precision)
         Read (s, *, iostat=ios) num
       Type Is (Real(Real128))
         Read (s, *, iostat=ios) num
     End Select



    End Subroutine

0 Kudos
1 Solution
Steven_L_Intel1
Employee
652 Views

First, this is not a compilation error - it's a runtime error. Second, if you got the error you indicated you're running on Linux, and this is the Windows forum. Third, your code excerpt did not show that the caller had an explicit interface for the subroutine - this is required if a dummy argument is polymorphic. If I make sure there is one, the program works for me.

View solution in original post

0 Kudos
2 Replies
Steven_L_Intel1
Employee
653 Views

First, this is not a compilation error - it's a runtime error. Second, if you got the error you indicated you're running on Linux, and this is the Windows forum. Third, your code excerpt did not show that the caller had an explicit interface for the subroutine - this is required if a dummy argument is polymorphic. If I make sure there is one, the program works for me.

0 Kudos
Vasili_M_
Beginner
652 Views

Apologies, you are correct Steve.

0 Kudos
Reply