搜尋此網誌

2016年8月5日 星期五

How to use __FILE__, __DATE__, __TIME__, __LINE__, __FUNCTION__, __FILE__ to debug in C?

================================================
__FILE__        current file nume.
__FUNCTION__    current functionnume.
__LINE__        current line number.
__DATE__        built date.

__TIME__        built time.
================================================

#include
#include
void call_test_fun(void);


#define DBG_PRINT(msg, arg...) printf("%s:%s(%d): " msg, __FILE__, __FUNCTION__, __LINE__, ##arg)

int main(void)
{
    printf( "The file is: %s\n", __FILE__ );
  
  printf( "This function is: %s\n", __FUNCTION__ );
    printf( "This is line: %d\n", __LINE__ );
    printf( "The date is: %s\n", __DATE__ );
    printf( "The time is: %s\n", __TIME__ );
    call_test_fun();
    return 0;
}

void call_test_fun(void)
{
    printf( "This function is: %s\n", __func__ );
    printf( "The file is: %s\n", __FILE__ );
    printf( "This is line: %d\n", __LINE__ );

    printf( "STDC: %d \n", __STDC__);
    printf( "STDC_HOSTED: %d \n", __STDC_HOSTED__);
    printf( "VERSION: %s \n", __VERSION__);
    printf( "TIMESTAMP: %s \n", __TIMESTAMP__);
    DBG_PRINT("number = %d, str = %s\n", index, str);
}

1 則留言:

  1. I will try to do my best. Thanks for your encouragement!

    回覆刪除