当前位置:网站首页>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 .
边栏推荐
- 如视技术副总裁杨永林:当传统产业遇到“数字空间”
- Day 5
- Thousands of databases, physical machines all over the country, JD logistics full volume cloud live record | interview with excellent technical team
- Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system
- 科班同学真的了解未来的职业规划吗?
- C语言 一维数组
- JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
- C语言数组入门到精通(数组精讲)
- Time complexity and space complexity
- 51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭
猜你喜欢

MySQL的基础概念+数据库系统结构+拓展延申+基础命令学习

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

阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署

携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”

【C语言系列】— 不创造第三个变量,实现两个数的交换

365天挑战LeetCode1000题——Day 035 每日一题 + 二分查找 13

抢先预约 | 阿里云无影云应用线上发布会预约开启

365天挑战LeetCode1000题——Day 042 数组序号转换 + 相对名次 离散化处理

【C语言系列】—深度解剖数据在内存中的存储(二)-浮点型

【活动预告】云上数字工厂与中小企业数字化转型创新论坛
随机推荐
容器安全开源检测工具--问脉 VeinMind(镜像后门、恶意样本、敏感信息、弱口令等)
如视技术副总裁杨永林:当传统产业遇到“数字空间”
C语言文件操作
JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
【C语言系列】—文件操作详解(上)
Live broadcast Preview: integration of JD cloud Devops and jfrog product library
NVIDIA Zhou Xijian: the last mile from design to digital marketing
Best practices for elastic computing in the game industry
数组学习之入门简单题 两数之和
Occt learning 003 - MFC single document project
Side effects and sequence points
321, Jingdong Yanxi × Nlpcc 2022 challenge starts!
C语言数组入门到精通(数组精讲)
C语言 N皇后问题
省市区三级联动(简单又完美)
365 day challenge leetcode 1000 questions - day 037 elements and the maximum side length of squares less than or equal to the threshold + the number of subsequences that meet the conditions
How to get command parameters in Visual Basic.Net
重定向和文件
阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署
321,京东言犀×NLPCC 2022挑战赛开赛!