F90 compiler and user defined types

  • Thread starter Thread starter santanaa
  • Start date Start date
  • Tags Tags
    Compiler
AI Thread Summary
The discussion centers on a Fortran 90 (f90) issue related to defining methods with the same name for different user-defined types. The user, a C++ programmer, is trying to create two types, "Box" and "Other," each with a method named "Print." However, the f90 compiler raises an error indicating that the procedure 'Print' is already defined, preventing the user from having both methods coexist. The user seeks a solution to allow both types to have a method named "Print," acknowledging that Fortran already includes an intrinsic print function. The challenge lies in the compiler's inability to distinguish between the two user-defined methods due to the same name, leading to the need for a workaround or alternative naming convention to resolve the conflict.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top