From c93071a5654fea9facc6e22b29c407f5b6e19760 Mon Sep 17 00:00:00 2001 From: rangersly <2281598291@qq.com> Date: Tue, 22 Apr 2025 13:37:15 +0800 Subject: [PATCH] FIX: specifier_qualifier fix const --- program/c_cpp/universal/specifier_qualifier.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/program/c_cpp/universal/specifier_qualifier.md b/program/c_cpp/universal/specifier_qualifier.md index 7f33229..36b5ca4 100644 --- a/program/c_cpp/universal/specifier_qualifier.md +++ b/program/c_cpp/universal/specifier_qualifier.md @@ -6,16 +6,19 @@ - [mutable](#mutable) - [thread local](#`thread_local`) - [const](#const) + -[const with point](# const-with-point) - [volatile](#volatile):强制读内存 - [restrict](#restrict) : 指示编译器优化指针(C99) ## static - 用在整个文件的声明中,表示内部连接性 - 局部声明中,代表存储持续性为静态 +- 用在整个文件的声明中,表示内部连接性 +- 局部声明中,代表存储持续性为静态 - 可将函数限制为内部连接性 - `static void show();` +- 可将函数限制为内部连接性 +> `static void show();` + +- 在c语言中常用于将内部函数与外部接口分离 ## extern 引用声明 @@ -37,6 +40,13 @@ 就像使用了static 如果希望连接性为外部,则可以用extern覆盖 +### const-with-point +```c +const int * p; // 指向常量的指针 +int *const p; // 指针常量(不可修改指向) +const int * const p; // 指针和被指向的都不可修改 +``` + ## restrict - 在没有 restrict 的情况下,编译器需要考虑指针之间可能存在的别名关系。编译器会频繁地从内存中读取数据,以确保每次使用指针时数据是最新的。这会导致不必要的内存访问 - 使用 restrict 后,编译器可以假设带有 restrict 的指针是唯一的,不会与其他指针指向同一块内存。因此,编译器可以减少不必要的内存访问