当前位置:网站首页>ANSI C type qualifier
ANSI C type qualifier
2022-07-29 05:28:00 【Ryan fitter】
ANSI C Type qualifier
1.const Type qualifier
With const Keyword declared object , Its value cannot be assigned or incremented 、 Decrement to modify .
Especially when using pointers, you need to pay attention to several points :
const float * pf;//pf Point to one float Type of const value
The above creation means pf The value on the address cannot be changed , and pf It can be changed .
float * const pt;//pt It's a const The pointer
The above represents pt Must point to the same address , But the value it points to can be changed .
const float * const ptr;
The above code indicates ptr Can't point anywhere , The value it points to cannot be changed .
float const * pfc;// And const float * pfc identical
The meaning of the above code is the same as that of the first sentence .
const int array[] And const int * array Both of them mean that they cannot be changed array Point to data .
2.volatile Type qualifier
volatile The qualifier represents a proxy ( Not the program where the variable is located ) You can change the value of this variable . It is usually used for hardware addresses and sharing data in threads run by other programs or colleagues .
Grammar and const equally :
volatile int loc1;//loc1 It's a volatile position
volatile int * ploc;//ploc Is a pointer to a variable position
Use volatile The reason for the keyword is that the compiler will temporarily store the value of a variable in a register , Read it from the register only when necessary ( Instead of reading it from the location of the original memory ), To save time , This is called cache . But if there is a numerical change between two agents, the compiler cannot recognize , To do this, you need to use volatile Keyword to ensure whether the value of the variable changes .
3.restrict Type qualifier
restrict Keyword allows the compiler to optimize a part of the code to better support computation . It can only be used for pointers , Indicates that the pointer is the only and initial way to access the data object .
If not used restrict keyword , The compiler must assume the worst case ( That is, other identifiers may have changed the data between the two uses of the pointer ). If used restrict Keyword can choose shortcut optimization calculation .
restrict Qualifiers can also be used for pointers in function parameters . Indicates that the compiler can assume that its identifier in the function body will not modify the data pointed to by the pointer , And the compiler can try to optimize it , Make it useless for other purposes .
4._Atomic Type qualifier
This qualifier is mainly in C11 Version implementation , Its main function is concurrent programming, which divides program execution into multiple threads that can be executed at the same time .
边栏推荐
- Best practices of JD cloud Distributed Link Tracking in financial scenarios
- More than 200 ISVs have settled in! The first anniversary of Alibaba cloud computing nest
- Teardown's method of lifting the time limit
- 167. Sum of two numbers II - enter an ordered array
- Day 5
- NVIDIA Zhou Xijian: the last mile from design to digital marketing
- CMU15-213 Malloc Lab实验记录
- Time complexity and space complexity
- QT learning: qdropevent drag event
- What is_ GLIBCXX_ VISIBILITY(default)
猜你喜欢

京东云金秋上云特惠进行中!扫码参与活动

研发效能生态完整图谱&DevOps工具选型必看

Helm chart for Kubernetes

Live broadcast Preview: integration of JD cloud Devops and jfrog product library

【C语言系列】— 打印100~200之间的素数

Alibaba cloud architect details nine trends in the game industry

B - 识别浮点常量问题

京东云分布式链路追踪在金融场景的最佳实践

Unity3d - the object is too far away to see

无重复字符的最长字串
随机推荐
R & D efficiency | analysis of kubernetes' core technology and Devops' landing experience
直播预告|如何通过“智能边缘安全”提升企业免疫力?
365天挑战LeetCode1000题——Day 040 设计跳表 + 避免洪水泛滥 + 查找大小为 M 的最新分组 + 销售价值减少的颜色球
Day 1
平行云CEO 李岩:CloudXR ,开启通往元宇宙的通道
200 多家 ISV 入驻!阿里云计算巢发布一周年
如视技术副总裁杨永林:当传统产业遇到“数字空间”
AiTalk创始人梁宇淇:镜像连接虚拟与现实的纽带
为啥谷歌的内部工具不适合你?
Xiaolu Inn - Trailer
数千个数据库、遍布全国的物理机,京东物流全量上云实录 | 卓越技术团队访谈录
【赛事预告】云上开发,高效智能——第二届阿里云ECS CloudBuild开发者大赛即将启动
Cryengine Technology
365天挑战LeetCode1000题——Day 042 数组序号转换 + 相对名次 离散化处理
51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭
Introduction to array learning simple question sum of two numbers
研发效能|Kubernetes核心技术剖析和DevOps落地经验
JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
Bubble sort c language
Unity3d - the object is too far away to see