FIX: specifier_qualifier fix const

This commit is contained in:
rangersly 2025-04-22 13:37:15 +08:00
parent 0e104a3721
commit c93071a565

View File

@ -6,16 +6,19 @@
- [mutable](#mutable) - [mutable](#mutable)
- [thread local](#`thread_local`) - [thread local](#`thread_local`)
- [const](#const) - [const](#const)
-[const with point](# const-with-point)
- [volatile](#volatile):强制读内存 - [volatile](#volatile):强制读内存
- [restrict](#restrict) : 指示编译器优化指针(C99) - [restrict](#restrict) : 指示编译器优化指针(C99)
## static ## static
用在整个文件的声明中,表示内部连接性 - 用在整个文件的声明中,表示内部连接性
局部声明中,代表存储持续性为静态 - 局部声明中,代表存储持续性为静态
可将函数限制为内部连接性 - 可将函数限制为内部连接性
`static void show();` > `static void show();`
- 在c语言中常用于将内部函数与外部接口分离
## extern ## extern
引用声明 引用声明
@ -37,6 +40,13 @@
就像使用了static 就像使用了static
如果希望连接性为外部则可以用extern覆盖 如果希望连接性为外部则可以用extern覆盖
### const-with-point
```c
const int * p; // 指向常量的指针
int *const p; // 指针常量(不可修改指向)
const int * const p; // 指针和被指向的都不可修改
```
## restrict ## restrict
- 在没有 restrict 的情况下,编译器需要考虑指针之间可能存在的别名关系。编译器会频繁地从内存中读取数据,以确保每次使用指针时数据是最新的。这会导致不必要的内存访问 - 在没有 restrict 的情况下,编译器需要考虑指针之间可能存在的别名关系。编译器会频繁地从内存中读取数据,以确保每次使用指针时数据是最新的。这会导致不必要的内存访问
- 使用 restrict 后,编译器可以假设带有 restrict 的指针是唯一的,不会与其他指针指向同一块内存。因此,编译器可以减少不必要的内存访问 - 使用 restrict 后,编译器可以假设带有 restrict 的指针是唯一的,不会与其他指针指向同一块内存。因此,编译器可以减少不必要的内存访问