Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29004 Discussions

Choosing lines of code to execute when compiled in Debug but not Release

Jason_Harp
Beginner
1,089 Views
I have a program I am debugging in which I have some data written to an output file. However when I am testing to code I don't really need those extra files slowing me down. I would like to not execute those write commands when I compile in RELEASE mode, but I often forget to comment out those lines before I compile. I've seen in some C programs I work with techniques to execute certain lines of code depending on the compiler options selected.

Does any one know a way to specify a line of code so that it is only compiled when the compiler is in DEBUG mode, but it does not compile in RELEASE mode?
0 Kudos
1 Solution
Les_Neilson
Valued Contributor II
1,089 Views

In your debugproject settings Fortran->Preprocessor->Preprocessor Definitions put DEBUG
Then in your code put :

!DEC$ IF DEFINED (DEBUG)
code to execute indebug mode only
!DEC$ ELSE
!DEC$ ENDIF

Les

View solution in original post

0 Kudos
4 Replies
Les_Neilson
Valued Contributor II
1,090 Views

In your debugproject settings Fortran->Preprocessor->Preprocessor Definitions put DEBUG
Then in your code put :

!DEC$ IF DEFINED (DEBUG)
code to execute indebug mode only
!DEC$ ELSE
!DEC$ ENDIF

Les
0 Kudos
Steve_Nuchia
New Contributor I
1,089 Views

There is also a project properties setting, fortran / language / compile lines with "D" in column 1 / boolean

0 Kudos
Greg_T_
Valued Contributor I
1,089 Views
Hello,

In addition to the compiler directives to control active code, we also use an integer or logical flag to control debugging and log file output. I like an integer variable so that levels or amounts of debugging output can be controlled as needed. Depending on how you are running the program, you can control the integer output flag from a command line input, a value from an input file, or even a slider bar in a GUI. Since we often have a GUI written in another language like Visual Basic, it is convenient to get debugging output from the release version by using our log file. Perhaps this approach would also be helpful for you.


Regards,
Greg
0 Kudos
Steven_L_Intel1
Employee
1,089 Views
The "D Lines" feature is for fixed-form source only. I do not recommend its use. The conditional compilation directives are the best choice.
0 Kudos
Reply