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

SELECT TYPE error

Naoto_N
Beginner
1,226 Views

 

The program “console.exe” including “SELETCT TYPE” in subroutine “int_chr” is terminated with error code 157, if the subroutines are stored in a static library.

The library is generated using a template “static library“ installed in Visual Studio 2019.

The same error is reported even if the console application is converted to QuickWin by comentouting the line “! use ifqwin.”

The program normally ends if the main program and all subroutines are compiled and linked at the same time. (i.e. without the library).

The compiler IFORT version is “2021.8.0 Build 20221119_000000”

 Am I missing something?

 

C:\xxxx>console

 direct

 int ="       12345 "

 chr ="abcde     "

 via subroutine

forrtl: severe (157): Program Exception - access violation

Image              PC        Routine            Line        Source

Console.exe        00ED13B5  _INT_CHR                    3  int_chr.f90

Console.exe        00ED10FB  _MAIN__                    25  Main.f90

 

Labels (1)
(Virus scan in progress ...)
(Virus scan in progress ...)
(Virus scan in progress ...)
(Virus scan in progress ...)
0 Kudos
1 Solution
mecej4
Honored Contributor III
1,194 Views

Since the subroutine int_chr takes an argument whose type may change from one call to the next, an explicit interface to it must be provided in each caller. You can, for example, surround the code of int_chr with "module xyz ...end module xyz", and add "use xyz" in the main program. Please note that this requirement is a basic rule of the language, and is independent of whether or not you use Quickwindows, call routines in a library, etc.

View solution in original post

4 Replies
Naoto_N
Beginner
1,219 Views

For convenience of reference, the codes are listed below.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

! program structure

!  main--+--int_chr(integer)

!        +--int_chr(character)

!        +--sub_int--+--int_chr(integer)

!        +--sub_chr--+--int_chr(character)

  program Base00_Main

! use ifqwin

  implicit none

  character(10) :: test_chr = 'abcde'

  integer(4)    :: test_num = 12345

  print *, 'direct'

  call sub_int(test_num)

  call sub_chr(test_chr)

  print *, 'via subroutine'

  call int_chr(test_num)

  call int_chr(test_chr)

  stop

  end program Base00_Main

 

  subroutine int_chr(in)

  class(*) :: in

  select type (in)

  type is (character(*))

    call sub_chr(in)

  type is (integer)

    call sub_int(in)

  end select

  return

  end subroutine int_chr

 

  subroutine sub_chr(in_chr)

  character(*) :: in_chr

  print *, 'chr ="', in_chr, '"'

  return

  end subroutine sub_chr

 

  subroutine sub_int(in_int)

  integer :: in_int

  print *, 'int ="', in_int, '"'

  return

  end subroutine sub_int

0 Kudos
mecej4
Honored Contributor III
1,195 Views

Since the subroutine int_chr takes an argument whose type may change from one call to the next, an explicit interface to it must be provided in each caller. You can, for example, surround the code of int_chr with "module xyz ...end module xyz", and add "use xyz" in the main program. Please note that this requirement is a basic rule of the language, and is independent of whether or not you use Quickwindows, call routines in a library, etc.

Naoto_N
Beginner
1,126 Views

Dear mecej4,
Thank you very much for your comment.

I have solved the problem.
The following INTERFACE block in the main program is enough to solve the problem. (no change in the subroutine)

program Base00_Main
! use ifqwin
implicit none
INTERFACE
  SUBROUTINE INT_CHR(IN)
  CLASS (*) :: IN
  END SUBROUTINE INT_CHR
END INTERFACE
character(10) :: test_chr = 'abcde'
       :
       :

Of course, the INTERFACE block can be included using USING xxx statements with MODULE xxx having the INTERFACE block.

It has explained as follows in Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference.

When a procedure is referenced, it must have an explicit interface in the following cases:
• If the procedure has a dummy argument that is one of the following:
       :
• A polymorphic object (an object declared with a CLASS statement)

       :

However, I still have doubts.

Why the program without the INTERFACE block normally ends if the program is built without the library?

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,098 Views

Think of the class(*) as an opaque container holding a buffer together with some control information (e.g. buffer size, pointer, type, ...)

With the interface, the address of the container is passed to the called routine (that demands the address of a container).

Without the interface, the address of the buffer is passed to the to the called routine causing havok.

The process is somewhat like passing an array. Does the called routine need the address of the array or the address of the array descriptor? Only the interface will tell.

Jim Dempsey

0 Kudos
Reply