What flags do you set for your GFORTRAN debugger/compiler to catch faulty code?

Bare minimum -Og/-O0 -O0 basically tells the compiler to make no optimisations. Optimiser can remove some local variables, merge some code blocks, etc. and as an outcome it can make debugging unpredictable. The price for -O0 option is very slow code execution, but starting from version 4.8 GCC compilers (including the Fortran one) accept a … Read more

Why is this a function declared inside the module and then used somewhere else in the same module not seen by the linker?

In the following, I’ll explain using the complete example below (which you can compile and link to try things): module mymodule contains integer function foo () foo = 1 end function integer function bar () integer :: foo bar = foo() end function end module program test use mymodule print *, bar() end In the … Read more

Where to put `implicit none` in Fortran

The implicit statement (including implicit none) applies to a scoping unit. Such a thing is defined as BLOCK construct, derived-type definition, interface body, program unit, or subprogram, excluding all nested scoping units in it This “excluding all nested scoping units in it” suggests that it may be necessary/desirable to have implicit none in each function … Read more