Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Debug macros
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
#DEFINE ndebug
BEFORE the include.
'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) :
#define assert(x) IF NOT (x) THEN ? "Assert failed at line ";__LINE__;" func "; _
__FUNCTION__;" file "; __FILE__:SLEEP:END IF
'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) :
#define debug_print(x,y) PRINT (x);(y);" line ";__LINE__;" func ";__FUNCTION__; _
" file ";__FILE__

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...
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.
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.

Forum Jump:

Users browsing this thread: 1 Guest(s)