
C
文章平均质量分 66
wzq2009
这个作者很懒,什么都没留下…
展开
-
神奇的container_of
linux内核里面有个container_of 方法(准确的说是个宏),可以根据结构体的某个字段获取整个结构体的信息,感觉蛮好用的,摘录下来。 #include <stdio.h> #define offsetof(type, member) (size_t)&(((type*)0)->member) #define container_of(ptr, type, m...原创 2020-01-17 12:10:55 · 194 阅读 · 0 评论 -
C的小特点
定义在struct内部的struct,也可以在struct外面使用,与定义在全局的效果是一样的。 #include <stdio.h> struct queue_t { int value; char key[100]; struct joint_t { int prev; int next; } joint; }; int main() { ...原创 2019-12-25 11:37:40 · 141 阅读 · 0 评论 -
透过汇编代码分析C语言的数据对齐(Data Alignment)与参数传递
C代码 #include <stdio.h> typedef struct S { short a; int b; long c; long d; long e; long f; long g; long h; short i; } S; void foo(S s) { printf("%hd, %d, %ld, %ld, %ld, %l...原创 2019-12-24 15:05:45 · 405 阅读 · 0 评论 -
C语言备忘录
C语言itoa()函数和atoi()函数详解(整数转字符C实现) C语言提供了几个标准库函数,可以将任意类型(整型、长整型、浮点型等)的数字转换为字符串。 1.int/float to string/array: C语言提供了几个标准库函数,可以将任意类型(整型、长整型、浮点型等)的数字转换为字符串,下面列举了各函数的方法及其说明。 ● itoa():将整型值转换为字符串。 ● ltoa():...原创 2019-12-06 15:03:08 · 217 阅读 · 0 评论 -
比较运算符 (== , != )的自动类型转换
比较运算符 (== , != )也会自动类型转换,例如下面的代码中语句 newp[j] != (index & 0xFF) , newp[j]会自动转换为int类型,还会进行符合扩展,使得本来期望是相等的结果不相等。语句 newp[j] != (char)(index & 0xFF) 进行了强制类型转换,比较的就是newp[j]的低8位,可以得到预期结果。也可以对newp[j...原创 2019-11-26 11:00:00 · 457 阅读 · 0 评论 -
Dangers of using dlsym() with RTLD_NEXT
Background There are times when you want to wrap a library function in order to provide some additional functionality. A common example of this is wrapping the standard library’smalloc()andfree()...转载 2019-11-05 18:10:06 · 223 阅读 · 0 评论 -
宏定义的黑魔法 - 宏菜鸟起飞手册
https://onevcat.com/2014/01/black-magic-in-macro/ 宏定义在C系开发中可以说占有举足轻重的作用。底层框架自不必说,为了编译优化和方便,以及跨平台能力,宏被大量使用,可以说底层开发离开define将寸步难行。而在更高层级进行开发时,我们会将更多的重心放在业务逻辑上,似乎对宏的使用和依赖并不多。但是使用宏定义的好处是不言自明的,在节省工作量的同时,代码...转载 2018-08-22 20:37:27 · 208 阅读 · 0 评论