宏
_Gorden_
多喝凉白开。
展开
-
实现strcat函数,assert宏(断言宏)使用介绍
strcat函数的实现代码如下:char* MyStrcat(char *dst, const char *src){ assert(dst != NULL && src != NULL); char *temp = dst; while (*temp != '\0') temp++; while ((*temp++ = *...原创 2019-12-28 17:52:39 · 292 阅读 · 0 评论 -
(offsetof宏、container_of宏)由结构体/类的实例的一个成员的地址,获取该结构体/类的实例的地址
这两个宏的源代码如下,大家用到的使用的一个方法是可以直接复制到自己的代码中使用。#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)#define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->memb...原创 2019-12-15 16:57:11 · 187 阅读 · 1 评论