当前位置:网站首页>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 .
边栏推荐
- Leetcode70 (Advanced), 322
- 2022.07.03(LC_6108_解密消息)
- Application of multi loop instrument in base station "switching to direct"
- [IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
- The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
- 【雅思阅读】王希伟阅读P3(Heading)
- 22-07-02周总结
- TS quick start - functions
- Nine Qi single chip microcomputer ny8b062d single key control four LED States
- P4408 [NOI2003] 逃学的小孩(树的直径)
猜你喜欢

It's too convenient. You can complete the code release and approval by nailing it!

ORB(Oriented FAST and Rotated BRIEF)

How many triangles are there in the golden K-line diagram?

人脸识别5- insight-face-paddle-代码实战笔记

Relationship between classes and objects

The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!

公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!

Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention

企业公司项目开发好一部分基础功能,重要的事保存到线上第一a

Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
随机推荐
2022.07.03 (LC 6108 decryption message)
JS convert pseudo array to array
How to use fast parsing to make IOT cloud platform
22-07-02周总结
How to effectively monitor the DC column head cabinet
(脚本)一键部署redis任意版本 —— 筑梦之路
Relationship between classes and objects
Is it safe to open an account in the College of Finance and economics? How to open an account?
Some basic functions of enterprise projects are developed, and important things are saved to online first a
Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
打新债开户注册安全吗?有没有风险的?靠谱吗?
abc 258 G - Triangle(bitset)
Illustrated network: what is gateway load balancing protocol GLBP?
PyTorch: In-place Operation
js如何实现数组转树
【北京大学】Tensorflow2.0-1-开篇
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
1189. Maximum number of "balloons"
IT转测试岗,从迷茫到坚定我究竟付出了什么?