Chinaunix首页 | 论坛 | 博客
  • 博客访问: 177156
  • 博文数量: 37
  • 博客积分: 1367
  • 博客等级: 中尉
  • 技术积分: 465
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-06 17:41
文章分类

全部博文(37)

文章存档

2015年(1)

2012年(17)

2011年(10)

2010年(1)

2009年(8)

我的朋友

分类: 嵌入式

2011-11-01 13:40:56

time_after(unsigned long a, unsigned long b)  //linux/jifiles.h

/*
*        These inlines deal with timer wrapping correctly. You are
*        strongly encouraged to use them
*        1. Because people otherwise forget
*        2. Because if the timer wrap changes in future you won't have to
*           alter your driver code.
*
* time_after(a,b) returns true if the time a is after time b.
*
* Do this with "<0" and ">=0" to only test the sign of the result. A
* good compiler would generate better code (and a really good compiler
* wouldn't care). Gcc is currently neither.
*/
#define time_after(a,b)                \
        (typecheck(unsigned long, a) && \
         typecheck(unsigned long, b) && \
         ((long)(b) - (long)(a) < 0))
里面用的typecheck宏,而这个宏的定义如下:
/*
* Check at compile time that something is of a particular type.
* Always evaluates to 1 so you may use it easily in comparisons.
*/
#define typecheck(type,x) \
({        type __dummy; \
        typeof(x) __dummy2; \
        (void)(&__dummy == &__dummy2); \
        1; \
})


typecheck宏中(void)(&__dummy == &__dummy2)检查两个指针变量类型是否一致,若不一致,gcc会报出警告,g++报出一个错误:
comparison of distinct pointer types lacks a cast

这样就进行了类型检查了。
阅读(1492) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~