/*
*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;
}
c misc test
原创
©著作权归作者所有:来自51CTO博客作者mb63982c735c3d9的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
从C 向C++13——模板
从C向C++13——模板
类模板 函数模板 数组 -
Misc string test
/* * std::string深入详解 * Visual Studio 2008Sp1, 使用Ctrl + F5启动调试 */#include #in
string 测试 character pig token -
linux下cmake编译opencv
1、下载安装CMake for Linux 下载地址:http://www.cmake.org/cmake/resources/software.html 我下载的版本是cmake-2.8.10.2,下载文件cmake-2.8.10.2.tar.gz 建立安装文件夹,
linux下cmake编译opencv ubuntu12.04 OpenCV2.4.4 Linux OpenCV