Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Debug macros
#1
Here's a pair of debug macros, copying c's ASSERT and VB's debug.print.

To use them, write them to .bi file, then include it in your programs. The macros are activated by default. When debug is ended, add
Code:
#DEFINE ndebug
BEFORE the include.
Code:
'debug macros by Antoni Gual
'-----------------------------------------------------------------------------
'ASSERT macro:if not defined ndebug, if assert is false it prints and exits,
'Use ask for a condition that should never happen:
'Example :assert(a<7)
'-----------------------------------------------------------------------------
#ifdef ndebug
#define assert(x) :
#else
#define assert(x) IF NOT (x) THEN ? "Assert failed at line ";__LINE__;" func "; _
__FUNCTION__;" file "; __FILE__:SLEEP:END IF
#endif
'
'-----------------------------------------------------------------------------
'DEBUG_PRINT if not defined ndebug, it prints value and the place where it is
'Example of use; debug_print("a$= ";a$)
'-----------------------------------------------------------------------------
#ifdef ndebug
#define debug_print(x,y) :
#else
#define debug_print(x,y) PRINT (x);(y);" line ";__LINE__;" func ";__FUNCTION__; _
" file ";__FILE__
#endif

C's ASSERT prints the asserted expression as well , but FB's maceos do not have the "stringize" operator yet.

Question to developers: could be a call to the crt assert function safely used?

I Hope you find them useful...
Antoni
Reply
#2
I guess it's would be a good idea to have another sub-forum only with code snippets ala the PB forums, or they will be lost in the middle of other topics.

I was going to add assert as an intrinsic macro when Angelo added the __FILE__ and such define's, but it was too late for the 0.13 release.
Reply
#3
A FB snippets section could be good, if
- Each thread allowed only one entry, the snippet, (editable by it's poster)

- Perhaps a maximum chars limit. Bigger things should be linked from separate URL
-People posted useful routines, not "see what I'm doing now" things.

This way the section could be an useful repository.
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)