F90 compiler and user defined types

  • Thread starter Thread starter santanaa
  • Start date Start date
  • Tags Tags
    Compiler
Click For Summary
SUMMARY

The discussion centers on the limitations of the F90 compiler regarding user-defined types and method overloading. Specifically, the user is attempting to define two subroutines named "Print" within different modules for distinct user-defined types, "Box" and "Other." The F90 compiler generates an error indicating that the procedure 'Print' is already defined, highlighting the lack of support for method overloading based on argument types in Fortran 90. To resolve this, users must adopt alternative naming conventions or encapsulate functionality within a single subroutine.

PREREQUISITES
  • F90 compiler knowledge
  • Understanding of Fortran user-defined types
  • Familiarity with Fortran modules
  • Basic knowledge of subroutine definitions in Fortran
NEXT STEPS
  • Research Fortran 90 naming conventions for subroutines
  • Explore encapsulation techniques in Fortran modules
  • Learn about method overloading alternatives in Fortran
  • Investigate the use of intrinsic functions in Fortran 90
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those transitioning from C++ or working on projects requiring user-defined types and subroutine management in Fortran 90.

santanaa
Messages
3
Reaction score
0
Hi I have a little issue with f90.

I am a c++ programmer but I have to use fortran for this project.

f90 the compiler does seem to distinguish between methods from user defined types. I have two types one "has a" instance of the other. Both have a methods named Print (with different typed arguments and in different modules). I want both of my user efined types to have the method named Print. The compiler won't let me define both!

here is an example

Code:
module BoxModule
type Box
...
end type
contains
subroutine Print(b)
type(Box) b
...
end subroutine
end module

module OtherModule
type Other
...
type(Box) b
...
end type
contains
subroutine Print(o) ! <----------------------------- compiler doesn't like this
type(Other) o
...
Print(o%b)
...
end subroutine
end module

here is the error

Code:
subroutine Print(c)
                1
use BoxModule
       2
Error: Procedure 'print' at (1) is already defined at (2)

Howe can I have both user dfeind type have a function named Print?
 
Technology news on Phys.org
I believe f90 already have a intrinsic print function.
 

Similar threads

  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
65
Views
5K
Replies
6
Views
3K
  • · Replies 16 ·
Replies
16
Views
6K
  • · Replies 43 ·
2
Replies
43
Views
4K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 70 ·
3
Replies
70
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K