当前位置:网站首页>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 .
边栏推荐
- If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
- [error reporting] "typeerror: cannot read properties of undefined (reading 'split')“
- 基于三维gis平台的消防系统运用
- 微服务(Microservice)那点事儿
- He worked as a foreign lead and paid off all the housing loans in a year
- Upload avatar on uniapp
- Oracle case: SMON rollback exception causes instance crash
- Is it safe to open an account in the College of Finance and economics? How to open an account?
- Parsing of XML
- Illustrated network: what is gateway load balancing protocol GLBP?
猜你喜欢

npm install报错 强制安装

Application of multi loop instrument in base station "switching to direct"
![P3304 [sdoi2013] diameter (diameter of tree)](/img/5c/984675bf4517481f80f54657c6c7ad.png)
P3304 [sdoi2013] diameter (diameter of tree)
Date time type and format in MySQL

【路径规划】RRT增加动力模型进行轨迹规划

A new method for analyzing the trend chart of London Silver

Continuous modification of business scenario functions
![[path planning] RRT adds dynamic model for trajectory planning](/img/98/dd9b106fd9dc64e676d9c943c03ab3.jpg)
[path planning] RRT adds dynamic model for trajectory planning

IELTS examination process, what to pay attention to and how to review?

Paper notes multi UAV collaborative monolithic slam
随机推荐
业务实现-日志写到同一个行数据里面
[selenium automation] common notes
How to do the project of computer remote company in foreign Internet?
TS快速入门-函数
22-07-02周总结
Advanced template
打新债开户注册安全吗?有没有风险的?靠谱吗?
Illustrated network: what is gateway load balancing protocol GLBP?
Tester's algorithm interview question - find mode
GDB common commands
MySQL uses the explain tool to view the execution plan
Safety learning week4
企业应用业务场景,功能添加和修改C#源码
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
A new method for analyzing the trend chart of London Silver
IELTS examination process, what to pay attention to and how to review?
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
【路径规划】RRT增加动力模型进行轨迹规划
Paper notes multi UAV collaborative monolithic slam
[IELTS reading] Wang Xiwei reading P3 (heading)