Switch off Debug

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Switch off Debug

Post by ndudman »

Sorry guys I know another question

I think I know the answer, but wanted to confirm, sorry if its simply

Is the only way to turn off debuging print lines gloabally... to create my own public sub say myPrintDebug() which I use instead of Debug.print, with a global variable (on/off)... or using #ifdefin DEBUG around the Debug.print lines ?

Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Your conjecture is correct. There isn't any built-in way to globally disable debug output.
- Don Kinzer
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post by Don_Kirby »

Neil, I believe it's a good idea to use the available Conditional Compilation Directives to globally enable and disable your debug output. Even when you are done writing your application, leave them in there. That goes for comments you may have added to help debug particular parts of the code. These are also useful for writing code that can work across multiple devices. Remember that when disabled, the compiler will optimize them out completely, so they use no space on the device.

I recently picked up again on a project that I had put on the back burner for 6 months. Some of the code was, let's just say 'a little vague'. What helped me more than my own comments were the debug outputs that were disabled, but still in the code.

In recent projects, I have also added a module to the project just for notes, errata, or other miscellany, as well as another module for a running change log. At the end of every programming session, I update these two documents . The extra few minutes has already shown it's helpfulness by making it easier to get back into the groove if I happen to be away from it for more than a few days.

-Don
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

Don

Thanks for the ideas... iḿ early on in a bigish project and with not so much practice yet... so these things really help to keep track of things.

I was thinking to combine the two so I can remove all debug for a build with conditionals and also disable debug with a global variable without recompilation and while running the uP... suedo code

Code: Select all

#define DEBUG 1

private const DEBUGON as boolean = TRUE
public function  myDebug(String msg) as String
   if (DEBUGON) then
        Debug.print msg
end function
#endif

#ifdef DEBUG
   myDebug(¨Debug message¨)
#endif
I know that conditional compilation with parameters isnt implemented in Zbasic (YET?) I woundered if the last 3 lines above could be put in a #define with parmeters to make all those myDebug() calls shorter. I was thinking of using inline c and the c #define with parameters to do this... but would still have to put #c/#endc around the debug lines... perhaps another --option for those with native node devices could be that #define could be ignored by zbasic and assumed to be inline c code. Anyway if in zbasic you wanted #defines you use the const. Or something like that ?

Just an idea...

Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

ndudman wrote:I was thinking to combine the two so I can remove all debug for a build with conditionals and also disable debug with a global variable without recompilation and while running the uP
You can do what you've describe but not with the code you've shown. The Const you defined can't be changed at run time; you'd have to re-compile if you wanted to change the value. If you want to be able to change it at run time you need to define it as a variable.
ndudman wrote: I woundered if the last 3 lines above could be put in a #define with parmeters to make all those myDebug() calls shorter.
At present, you'll have to type (or copy/paste) the lines. There is no text substitution mechanism in the ZBasic compiler.
- Don Kinzer
Post Reply