标签:
1. /* round up for aligment */
#define round_up(x, aligment) ( ( ( (x) + ((aligment) - 1) ) / (aligment) ) * (aligment) )
round_up(7, 5) = 10
2. 负数进行模运算 (-7 % 5 = 3 -> 7 加上 3 就可以被 5 整除)
void * memcpy (dstpp, srcpp, len) void *dstpp; const void *srcpp; size_t len; { unsigned long int dstp = (long int) dstpp; unsigned long int srcp = (long int) srcpp; /* Copy from the beginning to the end. */ /* If there not too few bytes to copy, use word copy. */ if (len >= OP_T_THRES) { /* Copy just a few bytes to make DSTP aligned. */ len -= (-dstp) % OPSIZ; BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ); ... }
3. list_entry
#define container_of(ptr, type, member) ({ const typeof( ((type *)0)->member ) *__mptr = (ptr); (type *)( (char *)__mptr - offsetof(type,member) );}) #endif
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
4. 获取一个数组的元素个数
#define SIZE_ARRAY(a) ( sizeof((a)) / sizeof((a[0])) )
标签:
原文地址:http://www.cnblogs.com/xiaokuang/p/4612669.html