简体   繁体   English

C中指针的这些易失性是什么意思?

[英]What's meaning of these volatile with pointers in C ?

volatile void * ptr;

Whether ptr is volatile or it points to the volatile location . ptrvolatile还是指向volatile location

So the actual doubt is : Is the same thing applied to the above declaration as it applied with const qualifier ? 所以实际的疑问是:同样的东西应用于上面的声明,因为它应用了const限定符?

Little explanation will help me a lot. 一点点解释都会对我有所帮助。

It's a pointer to volatile data. 它是指向易失数据的指针。 If the pointer itself should be volatile but not the data it points at, you'd use: 如果指针本身应该是易失性但不是它指向的数据,那么你可以使用:

void * volatile ptr;

So yes, it works the same way as the const modifier. 所以是的,它的工作方式与const修饰符相同。

A Microsoft explanation : 微软的解释

The volatile keyword specifies that the value associated with the name that follows can be modified by actions other than those in the user application. volatile关键字指定与后面的名称关联的值可以通过除用户应用程序中的操作之外的操作进行修改。

The volatile keyword is useful for declaring objects in shared memory that can be accessed by multiple processes. volatile关键字对于声明可由多个进程访问的共享内存中的对象很有用。

Both const and volatile are type qualifiers (they're the only type qualifiers in C, in fact). constvolatile都是类型限定符 (事实上​​它们是C中唯一的类型限定符)。 The syntax for using them is identical. 使用它们的语法是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM