当前位置:网站首页>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 .
边栏推荐
- 【活动预告】云上数字工厂与中小企业数字化转型创新论坛
- 携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”
- 321,京东言犀×NLPCC 2022挑战赛开赛!
- APP常用跨端技术栈深入分析
- 阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署
- 365天挑战LeetCode1000题——Day 037 元素和小于等于阈值的正方形的最大边长 + 满足条件的子序列数目
- JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
- Best practices of JD cloud Distributed Link Tracking in financial scenarios
- 【C语言系列】— 不创造第三个变量,实现两个数的交换
- C语言 N皇后问题
猜你喜欢

365天挑战LeetCode1000题——Day 041 二分查找完结纪念 + 第 N 个神奇数字 + 在线选举

直播预告:京东云DevOps与JFrog制品库的融合

365 day challenge leetcode1000 question - distance between bus stops on day 038 + time-based key value storage + array closest to the target value after transforming the array and + maximum value at t

QML control: combobox

如视技术副总裁杨永林:当传统产业遇到“数字空间”

Unity3d - the object is too far away to see

365天挑战LeetCode1000题——Day 040 设计跳表 + 避免洪水泛滥 + 查找大小为 M 的最新分组 + 销售价值减少的颜色球

Day 1

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

数据库操作 Day 6
随机推荐
Occt learning 002 - environment construction
一维数组练习
QML type: mousearea
321,京东言犀×NLPCC 2022挑战赛开赛!
CMU15-213 Shell Lab实验记录
力扣994:腐烂的橘子(BFS)
Li Yan, CEO of parallel cloud: cloudxr, opens the channel to the metauniverse
【C语言系列】—文件操作详解(上)
【C语言系列】—深度解剖数据在内存中的存储(二)-浮点型
vim编辑器使用
研发效能生态完整图谱&DevOps工具选型必看
阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署
APP常用跨端技术栈深入分析
携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”
预约中,2022京东云产业融合新品发布会线上开启
Bubble sort c language
平行云CEO 李岩:CloudXR ,开启通往元宇宙的通道
CMU15-213 Malloc Lab实验记录
Complete ecological map of R & D Efficiency & selection of Devops tools
QML custom tabbar