- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am developing an already existing code. When by mistake I insert a not declared variable in the code, for example because of a typo, the compiler don't give me back an error but define this variable by itself and set it to zero. In this way it takes a lot of time to find bugs.
How can I avoid it?
I'm compiling with:
ifort -O3 -axCORE-AVX2 -xSSE4.2 -ipo code.f -o code.exe -extend-source -r8 -lmpi -vec-report2
Thanks
GB
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Add "implicit none"
program YourProgram
use YourModule ! place modules here
implicit none
real :: YourDataHere
...
Do the same for subroutines and functions.
You should also make a test run with runtime diagnostics enabled (and compile time interface checking)
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the compiler don't give me back an error but define this variable by itself and set it to zero.
There are millions of lines of code in Fortran that use implicit typing, and it is not an error to use implicit typing. Some compilers may have an option to apply "IMPLICIT NONE" to all routines being compiled.
I can assure you that unless you ask for it, using the /Qzero or similar options, the compiler does not set local variables to zero. However, it may happen that the memory locations assigned to the variable contain zeros. A few minutes later, if you rerun the program, you may see different initial values. It is the programmer's responsibility to initialize variables using one of the available facilities.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As Jim suggested, it may help, especially in the long run, if you can introduce "implicit none" in your code.
Also, look into compiler warning options as shown here: https://software.intel.com/en-us/node/579575, particularly -warn declarations and unused.
You may also want to look into -init compiler specification and check if your code can handle signaling NaN, etc.: https://software.intel.com/en-us/node/579555
An additional option to consider is runtime checking: see -check uninit at https://software.intel.com/en-us/node/579521.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page