F90 compiler and user defined types

  • Thread starter santanaa
  • Start date
  • Tags
    Compiler
In summary, the conversation discusses an issue with the f90 compiler not allowing the definition of two different methods named "Print" for user-defined types. The individual is trying to have both of their user-defined types have a method named "Print" but the compiler is not allowing it. The conversation also mentions the possibility of an intrinsic print function in f90.
  • #1
santanaa
3
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
  • #2
I believe f90 already have a intrinsic print function.
 

1. What is the F90 compiler?

The F90 compiler is a software tool used for compiling and translating source code written in the Fortran 90 programming language into a form that can be executed by a computer. It is a crucial tool for developing and running programs written in Fortran 90.

2. How does the F90 compiler handle user defined types?

The F90 compiler has the ability to recognize and handle user defined types, also known as derived types, that are created by the programmer. It allows for the creation of custom data types and structures to better organize and manage data in a program.

3. What is the syntax for creating a user defined type in Fortran 90?

The syntax for creating a user defined type in Fortran 90 is as follows:

TYPE [type name]
  [type attributes]
  [component declarations]
 END TYPE [type name]

4. Can user defined types be used in functions and subroutines?

Yes, user defined types can be used in functions and subroutines just like any other data type in Fortran 90. They can be passed as arguments and returned as values, allowing for more versatile and modular code.

5. What are the benefits of using user defined types in Fortran 90?

There are several benefits to using user defined types in Fortran 90, including improved organization and readability of code, the ability to create custom data structures for specific purposes, and a more efficient use of memory. They also make it easier to update and modify code in the future.

Similar threads

  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
2
Replies
65
Views
2K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
2
Replies
43
Views
2K
  • Programming and Computer Science
3
Replies
70
Views
3K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
3
Views
324
  • Programming and Computer Science
Replies
16
Views
5K
Back
Top