当前位置:网站首页>Summary of the function and usage of const, volatile and restrict
Summary of the function and usage of const, volatile and restrict
2022-07-05 00:29:00 【Kingston】
const
const(constant) Keywords can modify variables 、 Function parameter 、 Return value or function body .
Define read-only variables .
Limiting function parameters . Prevent accidental modification . Increase program security and reliability .
Such as const char *p Express ,p The value pointed to by the pointer cannot be changed , This pointer cannot be used to modify data
Such as char *const p Express ,p The address pointed to by the pointer cannot be changed
Such as const int arr[] Then the values in the array cannot be modified
const char *const p Express , The value and address pointed to cannot be changed
const double locked[4]
double *pc=rates
pc=locked This sentence is illegal . because locked It can't be modified
In the source file const int i = 1 In other documents extern const int i, If in the header file, apply static const int i = 1, Because each file needs to contain this header file , need static Ensure internality . But if you store arrays in this way , Because each file needs to create this static array , It may take up more storage space , We need to consider its advantages and disadvantages from more aspects .
volatile
volatile Qualifiers indicate that variables can be modified by external agents in addition to programs , For example, the variable saves the current clock time .
The compiler optimizes the compilation and puts the unchanged value in the register , For reading , Mark volatile It can ensure that it is not put into the register .
If it cannot be changed by the program but can be changed by the agent const volatile int i.
restrict
restrict Can only be used for pointers int* restrict ptr, So that makes ptr Is the only way to point to a data block .
It can prevent data from being operated by other pointers . If in memcpy In order to prevent overlapping areas , use restrict Modifies the incoming pointer . meanwhile ,restrict It is also conducive to compiler optimization .
author : Hu hahaha
link :https://www.jianshu.com/p/58f618bd9ea3
source : Simple books
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
边栏推荐
- 兩個數相互替換
- Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
- AcWing164. 可达性统计(拓扑排序+bitset)
- What is the difference between port mapping and port forwarding
- [论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
- PyTorch: In-place Operation
- Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
- 实战模拟│JWT 登录认证
- Summary of week 22-07-02
- npm install报错 强制安装
猜你喜欢
【雅思阅读】王希伟阅读P3(Heading)
巩固表达式C# 案例简单变量运算
How to use fast parsing to make IOT cloud platform
Recursive execution mechanism
Application of fire fighting system based on 3D GIS platform
Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection
Paper notes multi UAV collaborative monolithic slam
[selenium automation] common notes
Face recognition 5- insight face padding code practice notes
随机推荐
Safety learning week4
2022.07.03(LC_6109_知道秘密的人数)
const、volatile和restrict的作用和用法总结
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
[Peking University] tensorflow2.0-1-opening
Oracle case: SMON rollback exception causes instance crash
业务实现-日志写到同一个行数据里面
MySQL uses the explain tool to view the execution plan
Upload avatar on uniapp
What is the difference between port mapping and port forwarding
业务场景功能的继续修改
Netcore3.1 JSON web token Middleware
(script) one click deployment of any version of redis - the way to build a dream
npm install报错 强制安装
TS quick start - functions
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
Enterprise application business scenarios, function addition and modification of C source code
Data on the number of functional divisions of national wetland parks in Qinghai Province, data on the distribution of wetlands and marshes across the country, and natural reserves in provinces, cities
Complete knapsack problem (template)