C语言
周厚平
Linux + 安卓 = 标配
展开
-
测试static int a,b; 的结果 (该结果可能与编译器版本有关, 尽量不要这样使用)
#include <stdio.h>/* 结果: a=2 b=2 a=3 b=3 a=4 b=4*/void fo(){ static int a=1,b=1; // 等价于static int a; static int b; a++; b++; printf("a=%d b=%d\n", a,b); // 2 3 4 return; }int main(){ fo(); fo(); fo(); return 0;}...原创 2020-07-26 18:30:36 · 669 阅读 · 1 评论 -
#pragma pack(push) #pragma pack(n) #pragma pack(pop)
// 参考bmp.h设置编译器使存储的结构体n字节对齐 #pragma pack(push) #pragma pack(n) // 强制让编译器内存对齐为:1字节对齐 /* 必须在结构体定义之前使用 */ // 在这儿定义多个结构体 // #pragma pack(pop) /* 恢复先前的pack设置 */如:#pragma pac...原创 2019-02-16 10:02:17 · 335 阅读 · 0 评论 -
i++和++i
#include <stdio.h>#include <unistd.h>int main(int argc, char **argv){ int i = 0; // 先用原来的i执行程序, 然后i再+1 printf("%d\n", i++); // 输出0 : i = 0; 执行程序; i += 1 = 1 printf("%d\n", i++); ...原创 2019-02-07 16:40:09 · 159 阅读 · 0 评论 -
2^n 字节对其算法(Linux内核)
来自Linux内核算法(kernel.h)#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))测试代码:#include <error.h>#include <errno.h>...原创 2019-01-28 10:24:27 · 481 阅读 · 0 评论 -
typeof关键字
转自: https://blog.csdn.net/qq_28349403/article/details/78921325使用typeof的声明示例下面是两个等效声明,用于声明int类型的变量a。typeof(int) a; /* Specifies variable a which is of the type int *...转载 2019-01-27 11:03:50 · 228 阅读 · 0 评论 -
终端字体打印特效 (设置封装)
0.使用方法: printf("字体属性""字体背景色")1.* \e 可用 \033 代替, \e表示 escape(转义字符),而 \033是 escape 的八进制值 *2.常用的ANSI控制码如下(有些不支持): 1.字体属性 \e[0m 关闭所有属性 \e[1m 高亮 \e[2m 亮度减半 \e[3m ...原创 2019-01-08 19:52:49 · 350 阅读 · 1 评论 -
"#"、"##"、可变参数打印、解析可变参数
1."#"、"##"的一般用法: #define STR(s) #s #define CONS(a,b) int(a##e##b) int main() { printf(STR(vck)); // 输出字符串"vck" printf("%d\n", CONS(2,3)); // 2e3 输出:20...原创 2019-01-08 19:25:47 · 270 阅读 · 0 评论 -
va_start()、va_list()、va_arg()、va_end() (variable)
转:https://blog.csdn.net/garygeeker/article/details/24248573源码: typedef void* va_list; void va_start (va_list ap, prev_param ); /* ANSI version */ typedef va_arg(va_list a...转载 2019-01-08 19:21:04 · 114 阅读 · 0 评论 -
glibc 库双向链表操作--解析(源码: list.h)
注意: 1.使用时包含头文件<List.h> 2.或者<tls.h> 3.如果头文件不存在就将以下代码另存且包含: include "list.h" 4.Linux内核在<linux/list.h>目录下也提供了链表操作函数, 但是接口不太一样, 但是功能更全以下是源代码及其使用方法:...原创 2019-01-07 21:17:55 · 907 阅读 · 2 评论 -
list_splice (拼接两个链表)
/* 拼接两个链表: 1.如果新增的链表只有一个链表头就不做任何处理(因为链表头不包含数据) 2. (head 2) + (add 4 5) ==> (head (5 6) 2 3) // 抛弃链表头add */ /* Join t...原创 2019-01-07 21:10:38 · 1620 阅读 · 1 评论 -
list_for_each()、 list_for_each_prev () 、list_for_each_prev_safe()函数
#define list_for_each(pos, head) \ for (pos = (head)->next; pos != (head); pos = pos->next)目的: 它实际上是一个for循环,从第一个节点开始(链表头不算做节点),pos = 第1个节点指针; 然后又向后移动一个节点, pos = 第2个节点指针...;直到到达最后一个节...原创 2019-01-07 19:47:38 · 1365 阅读 · 0 评论 -
list_entry函数分析
#define list_entry(ptr, type, member) \ ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))目的: 目的: // 根据节点ptr的地址,得到其type结构体的首地址, member是type结构体中的节点变量名 根据节点ptr, ...原创 2019-01-07 19:12:36 · 889 阅读 · 0 评论 -
Inline的应用
// 转 https://blog.csdn.net/lishuiwang/article/details/4637274?utm_source=blogxgwz2 内联(Inline)的定义以及什么情况下使用内联(转)内联函数也称为内嵌函数,它主要是解决程序的运行效率。函数调用需要建立栈内存环境,进行...转载 2019-01-07 11:25:50 · 431 阅读 · 0 评论 -
数据范围
// 转: https://blog.csdn.net/GS_MY/article/details/21863403 首先跟大家说一下,以下总结全来自谭浩强教授这本书的记录,我想很多人当初都不屑于记有多少个字节,但是每每做题的时候或者考试的时候都会碰到这些问题,每次问到有多少字节就翻江倒海的回忆然后不确定,现在,请往下看:一般数据类型有的...转载 2019-01-05 19:24:43 · 1892 阅读 · 2 评论 -
(union, struct) 相互嵌套使用----技巧(你肯定没见过)
#include <stdlib.h>#include <stdio.h>// 参考 Glibc库源码 sig_info.htypedef struct info{ int age; union { int code; struct { int pid; int uid; } id; struct { int KM; ...原创 2018-12-25 11:15:44 · 9887 阅读 · 1 评论