Simplest Fortran Code Still Has an Error -
i'm learning fortran new job , started writing very, basic programs. compile, i'm using gcc version 4.6.2, , i'm working on linux suse os (if matters @ all). believe version of fortran i'm using f90 or f95. code written using vim text editor.
here program i've written
integer, parameter :: x = 2, y = 3 integer :: z = x+y print *, z that's it! oh, , lines indented, start on column 8, indentation isn't issue.
update 1 have tried doing so:
program print_stuff print *, z end program print_stuff i tried adding implicit none statement of , didn't change in error. end update 1
i save, quit, , compile. compiler returns error:
error: unexpected end of file in 'practice1.f' anyone know problem is? i've tried removing print statement , having variable declarations same error occurs. it's keeping me practicing fortran @ all!
your first version
integer, parameter :: x = 2, y = 3 integer :: z = x+y print *, z is not valid fortran program. every valid program ends end statement. 'program' without end statement not syntactically correct. keep reading introductory tutorial.
i suggest habit of starting programs program statement, name, such as
program myprog and ending them with
end program myprog strictly, neither program statement nor program name necessary make things bit more comprehensible.
oh, , while i'm writing ... don't habit of starting lines @ column 8, smacks of out-dated fixed-form source. if using reasonable compiler (such gcc) give filenames .f90 suffix , let source code run free. while observing habits of indentation of course.
edit in response op's edits
program print_stuff print *, z end program print_stuff and
integer, parameter :: x = 2, y = 3 integer :: z = x+y print *, z end are both syntactically correct. both gfortran (v4.1.2) , intel fortran (v13.0.1) compile both correctly , produce executables execute.
Comments
Post a Comment