/* *author : davidlin *Date : 2014-12-26pm *email : [email protected] or [ email protected] *world : the city of SZ, in China *Ver : 000.000.001 *for : threads for rxtx! *history : editor time do * &NBSP;1) linpeng 2014-12-26 created this file! * &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;2) */ /* assert_self.h */#ifndef __assert_self_h__#define __ Assert_self_h__#include<stdio.h> #define ASSERT_ENABLE (1) # define xprintf printf /* xprintf can be tty print or uart print, etc */#if ASSERT_ENABLE#define Assert_error () do { xprintf ("[error] assert file: %s: line %d\n", __file__, __line__); \ }while (0) #define &NBSP;&NBSP;&NBSP;&NBSP;ASSERT1 (para) do { if (!para) { assert_error (); } }while (0) #else /* if ! assert_enable */ #define &NBSP;&NBSP;&NBSP;&NBSP;ASSERT1 (para) do &NBSP;&NBSP;&NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF (para) { } }while (0)  , #endif /* end of assert_enable */#endif /* end of __assert_self_h__*/
Test Cases
/* Test case:test.c */#include <stdio.h> #include "assert_self.h" int main (int argc, char* argv[]) {switch (ARGC) {Case 2:assert1 (atoi (argv[1])); break;default:printf ("ARG ACCEPT 1\n"); Break } exit (0);}
Software bug positioning, many times, such as the use of the Assert macro, you can compress 48 hours of debugging meal into 1 can eat dessert, each software team is re-evolution, the past experience is always not a good inheritance, this is us!
Software debug: Use assert Assert macro to locate software bug