I have a simple Fortran program with a derived type (TYPE). It compiles and runs perfectly with nvfortran, but gfortran gives me compilation errors about the derived type not being defined.
module classmodule
implicit none
type :: car
character(10) :: color
real :: fuel
end type car
contains
subroutine createcar(car, color, fuel)
type(car), intent(out) :: car
character(*), intent(in) :: color
real, intent(in) :: fuel
car%color = color
car%fuel = fuel
print*, color , fuel
end subroutine createcar
end module classmodule
program test_derived_type
use classmodule
implicit none
type(car) :: mycar
call createcar(mycar, "red", 50.0)
end program test_derived_type
$ gfortran --version
GNU Fortran (Ubuntu 15.2.0-16ubuntu1) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.$ gfortran test.f90 -o test
test.f90:10:12:10 | type(car), intent(out) :: car
| 1
Error: Derived type ‘car’ at (1) is being used before it is defined
test.f90:13:7:13 | car%color = color
| 1
Error: Symbol ‘car’ at (1) has no IMPLICIT type
test.f90:14:7:14 | car%fuel = fuel
| 1
Error: Symbol ‘car’ at (1) has no IMPLICIT type
test.f90:9:22:9 | subroutine createcar(car, color, fuel) | 1~~Error: Symbol ‘car’ at (1) has no IMPLICIT type
test.f90:21:7:21 | use classmodule
| 1
Fatal Error: Cannot open module file ‘classmodule.mod’ for reading at (1): No such file or directory
compilation terminated.
with nvfortran
$ nvfortran test.f90 -o test
$ ./test
red 50.00000
With windows gfortran
C:\Users\Shahid\Desktop>gfortran test.f90 -o test
test.f90:10:12:10 | type(car), intent(out) :: car
| 1
Error: Derived type ‘car’ at (1) is being used before it is defined
test.f90:13:7:13 | car%color = color
| 1
Error: Symbol ‘car’ at (1) has no IMPLICIT type
test.f90:14:7:14 | car%fuel = fuel
| 1
Error: Symbol ‘car’ at (1) has no IMPLICIT type
test.f90:9:22:9 | subroutine createcar(car, color, fuel) | 1~~Error: Symbol ‘car’ at (1) has no IMPLICIT type
test.f90:21:7:21 | use classmodule
| 1
Fatal Error: Cannot open module file ‘classmodule.mod’ for reading at (1): No such file or directory
compilation terminated.