compilation - This FORTRAN code shouldn't compile. Is there a reason why it does? -
the following code compiles, not think should. can see, output garbage.
this minimal failing example of bit me hard in large project work on.
my question - why compiler not complain? compiler limitation, or somehow "expected behaviour", , i've missed something?
i'm using gfortran 4.6.3.
module datamodule integer :: datum1 = int(1) integer :: datum2 = int(2) end module datamodule program moduletest use datamodule, only: datum1 write(*,*) "datum 1 is", datum1 write(*,*) "datum 2 is", datum2 end program moduletest
example output:
datum 1 1 datum 2 4.58322689e-41
your code @ fault, not compiler. if datum2
use associated despite only
clause , if explicit initialization of datum2
ignored, yes, naughty compiler.
the answer more mundane, though.
datum2
not use associated: in absence of implicit none
implicitly typed variable in main program. "garbage" comes fact not defined, initialization or assignment, before value referenced , it's implicitly (default) real. compiler isn't required detect mistake @ compile (or run) time.
Comments
Post a Comment