- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In building code by debug mode, PRINT or WRITE of variables on screen are needed but not in release mode.
If possible, I want to make this PRINT routine control by compiler directives such as
!DEC$ ()...
SOME PRINT STATEMENT ONLY ACTIVATE IN DEBUG MODE, NOT IN RELEASE MODE
!DEC$ ()
Thanks,
HK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to set a value in
Project Properties - Fortran - General - Preprocessor Definitions
For example I have set these two:
ONLINE; DEBUG
In my code I can now check:
[fortran]
!DEC$ IF DEFINED (ONLINE)
i = 1
!DEC$ ELSE
i = 2
!DEC$ END IF
!DEC$ IF .NOT. DEFINED (ONLINE)
i = 2
!DEC$ END IF
!DEC$ IF DEFINED (DEBUG)
nz = nz * 4
!DEC$ END IF
[/fortran]
I don´t think that this is case senstive.
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Id there any way to use !DEC$ IF for debug without having to actual set a Pre-processor Definitions. It would be good to have some code that is only for debug but without some auto detection there is more risk of getting it wrong....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
app4619 wrote:
Id there any way to use !DEC$ IF for debug without having to actual set a Pre-processor Definitions. It would be good to have some code that is only for debug but without some auto detection there is more risk of getting it wrong....
I believe _DEBUG gets defined by default in Visual Studio if the configuration is DEBUG. But you would still need !DEC$ IF DEFINED (_DEBUG) in your code to make use of it. But then another problem is one can undefine this definition in a Visual Studio setting and if that's done, the code will not process as intended. Also, a thing to note is at the command-line level, everything is based on selected options whether by Visual Studio or by the user directly. As far as I know, there is no built-in setting if -g (debug compile) option is specified at the command level. So I'm not sure there is any way to ensure reliable "auto detection". It is probably better for code developers to be conscious about it and do things correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the thoughts I will check that out and have a play with this area to find the compromise that works best for me.
FortranFan wrote:
!DEC$ IF It is probably better for code developers to be conscious about it and do things correctly.
This is clearly true, however, many things can and do go wrong so reducing the list of things that can go wrong stands a good chance reducing the number of things that do go wrong.
Perhaps setting defining mydebug=0 or 1 in the release and debug settings and in the case that mydebug is undefined have a line of dependant code the causes the compiler to cough and throw its teddy out of the pram. That is pure theorising as I have not yet investigated what is possible....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tested (DEBUG)
is not working. It is true that _DEBUG gets defined by default in Visual Studio if the configuration is DEBUG.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
_DEBUG is defined if you link to the debug libraries - it is not a sufficient test for a debug configuration. You would probably want to add your own preprocessor symbol to test for configurations.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page