> gfortran -fimplicit-none -Werror=implicit-interface main.f90 hello_world.f90 -o hello_world
main.f90:2:31:
2 | call hello_world("You there")
| 1
Error: Procedure ‘hello_world’ called with an implicit interface at (1) [-Werror=implicit-interface]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| subroutine hello_world(name) | |
| write(*,*) "Hello World: ", name | |
| end subroutine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > gfortran main.f90 hello_world.f90 -o hello_world | |
| > ./hello_world | |
| Hello World 544567129 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| subroutine hello_world(name : character(len=*)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| program main | |
| implicit none | |
| call hello_world("You there") | |
| contains | |
| include 'hello_world.f90' | |
| end program |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| program main | |
| interface | |
| subroutine hello_world(name) | |
| character(len=*) :: name | |
| end subroutine | |
| end interface | |
| implicit none | |
| call hello_world("You there") | |
| end program |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module hello_world_mod | |
| contains | |
| subroutine hello_world(name) | |
| implicit none | |
| write(*,*) "Hello World: ", name | |
| end subroutine | |
| end module |
# We will come back to the -fimplicit-none later
> gfortran -c -Werror=implicit-interface hello_world.f90
> gfortran -Werror=implicit-interface main.f90 -o hello_world
main.f90:3:31:
3 | call hello_world("You there")
| 1
Error: Type mismatch in argument ‘name’ at (1); passed CHARACTER(1) to INTEGER(4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module hello_world_mod | |
| contains | |
| subroutine hello_world(name) | |
| implicit none ! This should be present in all procedures | |
| character(len=*) :: name | |
| write(*,*) "Hello World: ", name | |
| end subroutine | |
| end module |
# create hello_world_mod.mod and hello_world.o > gfortran -c -fimplicit-none -Werror=implicit-interface hello_world.f90 # create main.o > gfortran -c -fimplicit-none -Werror=implicit-interface main.f90 # link and create hello_world binary > gfortran main.o hello_world.o -o hello_world # Execute the program > ./hello_world
OlderNewer