c misc test

来源:互联网 发布:mac python include 编辑:程序博客网 时间:2024/05/16 10:46
/*
 *Filename: hl.c
 *Author: hemmingway <hemmingway@163.com>
 *Description: this a misc practice program
 *Compile with: gcc -g -Wall -o hl.debug  hl.c
 */


#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>


#define ENABLE_DEBUG 1   //else, comment this line
#ifdef ENABLE_DEBUG
#define DEBUG_LOG(fmt,...) fprintf(stderr, "%s:%d: " fmt "\n",   \
__func__, __LINE__, ## __VA_ARGS__)
#else
#define DEBUG_LOG(fmt, ...) do {} while (0)
#endif


/*question: does this line can be works??*/
// #define DEBUG_LOG(fmt,...) fprintf(stderr, "%s:%d: " (fmt) "\n",__func__, __LINE__, ## __VA_ARGS__)




int max(int i, int j)
{
if(i>i)
return (i);
else
return (j);
}


int main()
{
int i, j, k;
i = 3;
j = 5;


time_t timep;
struct tm *tim;
char *p;
timep = time((time_t *)NULL);
tim = gmtime(&timep);
p = malloc(30*sizeof(char));
strncpy(p, ctime(&timep), 30);
printf("hello, world..now time is:%d-%d-%d %d:%d:%d\n", 1900 + tim->tm_year,1+ tim->tm_mon, 
tim->tm_mday,8 + tim->tm_hour, tim->tm_min, tim->tm_sec);
k = max(i,j);
printf("ctime: %s, max: %d\n",p, k);


//test c99 comment


//c89
printf( "The file is %s. \n", __FILE__ );
    printf( "The date is %s. \n", __DATE__ );
    printf( "The time is %s. \n", __TIME__ );
    printf( "This is line %d. \n", __LINE__ );
    printf( "__STDC__ is: %d \n", __STDC__ );




//c99
    printf( "This function is %s. \n", __func__ );  //__func__ c99的当前调用的函数名


//test debug_log


printf("\n\ntest debug log macro.\n\n");
    
DEBUG_LOG("Registering domain event cbs");
DEBUG_LOG("debug time, ctime: %s", p);




free(p);

return 0;
}