10 2012 档案
使用宏来打印变量
摘要:#define PRINT_INT( n ) printf( #n " = %d\n", n )#define PRINT_STRING( s ) printf( #s " = %s\n", s )//使用方法void test(void){ int a = 0; char str[] = "test string"; a++; PRINT_INT(a); PRINT_STRING(str);} 阅读全文
posted @ 2012-10-24 23:14 林德伟 阅读(209) 评论(0) 推荐(0)
linux 文件操作
摘要:一、open#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>int open(const char *pathname, int flags);int open(const char *pathname, int flags, mode_t mode);//返回值:成功返回新分配的文件描述符,出错返回-1并设置errnoopen函数在C代码里面的实际声明为int open(const char *pathname, int flags, ...);其中flags的主先参数有,O_RDO 阅读全文
posted @ 2012-10-23 22:22 林德伟 阅读(297) 评论(0) 推荐(0)
C语言工具宏之源文件、行号、日期、时间
摘要:__LINE__ 当前语句所在的行号, 以10进制整数标注.__FILE__ 当前源文件的文件名, 以字符串常量标注.__DATE__ 程序被编译的日期, 以"Mmm dd yyyy"格式的字符串标注.__TIME__ 程序被编译的时间, 以"hh:mm:ss"格式的字符串标注, 该时间由asctime返回. 阅读全文
posted @ 2012-10-18 22:27 林德伟 阅读(208) 评论(0) 推荐(0)
C语言巧用宏来添加调试信息
摘要:在编写嵌入式设备程序的时候,往往需要用printf函数来跟踪程序的运行情况,但当程序越来越大时,printf就用得越多,打印的信息也就多了起来。程序发布之前,我们又往往会把printf去掉。这种做法不仅费时,而且是对工作成果的一种浪费,如果下一次想要查看调试信息的时候,就回不来了。 我们现在就用宏来解决这个问题//log.h#ifndef LOG_H#define LOG_H//#define LOG_FILE //以文件的形式输出#define LOG_PRINT //以printf的形式输出 //如果都不定义,则不输出#if... 阅读全文
posted @ 2012-10-18 21:56 林德伟 阅读(790) 评论(0) 推荐(0)