Software debug: Use assert Assert macro to locate software bug

Source: Internet
Author: User

/*     *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)   &nbsp, #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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.