Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6947367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:41:04+00:00 2026-05-27T13:41:04+00:00

As the following code sample shows, person_list is a user-derived type and contains a

  • 0

As the following code sample shows, person_list is a user-derived type and contains a type-bound procedure compare_persons. I would like compare_persons to be able to accept a certain group of compareFunc as one of its arguments, and therefore declare the interface section for compareFunc. Note the first argument of compareFunc is of type person_list. (As you might tell, person_list is like TStringList in Delphi’s VCL.)

The compilation cannot proceed. The error messages are:

[root@localhost new]# ifort -c lib1.f90 
lib1.f90(26): error #6457: This derived type name has not been declared.   [PERSON_LIST]
                    TYPE(person_list) :: persons    !   error #6457: This derived type name has not been declared.   [PERSON_LIST]
-------------------------^
lib1.f90(23): error #6404: This name does not have a type, and must have an explicit type.   [PERSONS]
                FUNCTION compareFunc(persons, index1, index2)    !   error #6404: This name does not have a type, and must have an explicit type.   [PERSONS] 
-------------------------------------^
compilation aborted for lib1.f90 (code 1)

The error messages seem to indicate a circular reference between modules? I am therefore wondering how to declare the interface section for a procedure argument, which in turn references to a user-derived type of the same module? Any insights will be appreciated!

PS: The reason to try this module is the preference of OO programing style. The reason to try fortran is a big code base.

PS: The compiler is Intel Fortran Compiler, and the version is as the follows:

[root@localhost new]# ifort --version
ifort (IFORT) 12.1.0 20111011
Copyright (C) 1985-2011 Intel Corporation.  All rights reserved.

The code sample is:

MODULE lib1

    TYPE person_list

    CONTAINS
        PROCEDURE, PASS :: compare_persons

    END TYPE

CONTAINS

    FUNCTION compare_persons(this, index1, index2, compareFunc)

        IMPLICIT NONE

        INTEGER :: compare_persons
        CLASS(person_list) :: this
        INTEGER, INTENT(IN) :: index1
        INTEGER, INTENT(IN) :: index2

        INTERFACE
            FUNCTION compareFunc(persons, index1, index2)    !   error #6404: This name does not have a type, and must have an explicit type.   [PERSONS] 
                IMPLICIT NONE
                INTEGER :: compareFunc
                TYPE(person_list) :: persons    !   error #6457: This derived type name has not been declared.   [PERSON_LIST]
                INTEGER :: index1
                INTEGER :: index2
            END FUNCTION compareFunc
        END INTERFACE

        compare_persons = compareFunc(this, index1, index2)

    END FUNCTION compare_persons

END MODULE lib1

tpg2114 figures out the solution!

MODULE lib1

    TYPE person_list

    CONTAINS
        PROCEDURE, PASS :: compare_persons

    END TYPE

    INTERFACE
        FUNCTION CompareFuncInterface(persons, index1, index2)  
            IMPORT person_list
            IMPLICIT NONE
            INTEGER :: CompareFuncInterface
            TYPE(person_list), INTENT(IN) :: persons    
            INTEGER, INTENT(IN) :: index1
            INTEGER, INTENT(IN) :: index2
        END FUNCTION CompareFuncInterface
    END INTERFACE

CONTAINS

    FUNCTION compare_persons(this, index1, index2, compareFunc)

        IMPLICIT NONE

        INTEGER :: compare_persons
        CLASS(person_list), INTENT(IN) :: this
        INTEGER, INTENT(IN) :: index1
        INTEGER, INTENT(IN) :: index2
        PROCEDURE (CompareFuncInterface) :: compareFunc

        compare_persons = compareFunc(this, index1, index2)

    END FUNCTION compare_persons

END MODULE lib1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:41:05+00:00Added an answer on May 27, 2026 at 1:41 pm

    Okay, I figured it out:

    MODULE lib1
    
       TYPE :: persons
       CONTAINS
          PROCEDURE, PASS :: compare_persons
       END TYPE persons
    
       INTERFACE
          INTEGER FUNCTION compareFunc_interface(personsIn, index1, index2)
             IMPORT persons
             IMPLICIT NONE
             TYPE(persons), INTENT(IN) :: personsIn
             INTEGER, INTENT(IN) :: index1
             INTEGER, INTENT(IN) :: index2 
          END FUNCTION compareFunc_interface
       END INTERFACE
    
    
    CONTAINS 
       FUNCTION compare_persons(this, index1, index2, compareFunc)
          IMPLICIT NONE
    
          INTEGER :: compare_persons
          CLASS(persons) :: this
          INTEGER :: index1
          INTEGER :: index2
          PROCEDURE(compareFunc_interface) :: compareFunc
       END FUNCTION compare_persons
    END MODULE lib1
    

    From the 2003 standard, the IMPORT statement brings a definition from the host scoping unit to the local scoping unit. If you were using something from a different module, the INTERFACE would need a USE statement. But since you are importing from the higher up scoping unit, you use IMPORT and a list of the things you would like to bring into that scope

    Edit

    Also note, I added PASS to the declaration of the type-bound procedure. Although not required (because this is the default action), I prefer to always put PASS or NOPASS so that the intention is always explicit. This helps both the programmer (making sure they do what they think they are doing) and anybody who reads the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Dictionary bound to DataGridView by using following sample code. DataGridView bound
The following code sample shows how to serialize/deserialize to a file. How could I
The goal of the following code sample is to read the contents of $target
Given the following code sample: uint8_t i, in, ni; i = in = 2;
I have the following code sample that im trying to wrap my head around
I have the following sample code in a VB.NET console application. It compiles and
I have the following sample code which doesn't seem to want to run. import
I am new to Emacs, and I have the following code as a sample.
I'm following the sample code in CFNetwork Programming Guide , specifically the section on
In the sample code, the line with the 'error comment' gives the following the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.