- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Apologies, you are correct Steve.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page