当前位置:网站首页>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 .
边栏推荐
- 人生无常,大肠包小肠, 这次真的可以回家看媳妇去了。。。
- "Xiaodeng" domain password policy enhancer in operation and maintenance
- 实战模拟│JWT 登录认证
- Application of fire fighting system based on 3D GIS platform
- 【雅思阅读】王希伟阅读P3(Heading)
- The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
- Hisilicon 3559 universal platform construction: YUV422 pit stepping record
- Advanced template
- Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
- P3304 [sdoi2013] diameter (diameter of tree)
猜你喜欢

2022.07.03(LC_6111_统计放置房子的方式数)

2022.07.03 (lc_6111_counts the number of ways to place houses)
![[path planning] RRT adds dynamic model for trajectory planning](/img/98/dd9b106fd9dc64e676d9c943c03ab3.jpg)
[path planning] RRT adds dynamic model for trajectory planning

Fast parsing intranet penetration helps enterprises quickly achieve collaborative office

What is the difference between port mapping and port forwarding

2022.07.03(LC_6108_解密消息)

1189. Maximum number of "balloons"

基本放大电路的学习

Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet

leetcode518,377
随机推荐
P4408 [noi2003] truant children (tree diameter)
2022.07.03 (LC 6108 decryption message)
【Unity】InputSystem
Acwing164. Accessibility Statistics (topological sorting +bitset)
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
Identifiers and keywords
Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
P3304 [SDOI2013]直径(树的直径)
微服务(Microservice)那点事儿
[path planning] RRT adds dynamic model for trajectory planning
abc 258 G - Triangle(bitset)
Two numbers replace each other
Parsing of XML
Summary of week 22-07-02
Deux nombres se remplacent
Face recognition 5- insight face padding code practice notes
Using fast parsing intranet penetration to realize zero cost self built website
How to avoid arc generation—— Aafd fault arc detector solves the problem for you
P4408 [NOI2003] 逃学的小孩(树的直径)
Daily practice (18): stack containing min function