c - 出现在数组下标中的 "volatile"关键字的目的是什么?

标签 c arrays volatile function-parameter

在浏览cppreference时,我在函数参数中看到了一个奇怪的类型数组,如下所示:

void f(double x[volatile], const double y[volatile]);

那么,volatile 关键字出现在数组下标中的目的是什么?它有什么作用?

最佳答案

volatile关键字用于声明函数参数的数组类型。

这里,double x[volatile] 等同于double * volatile x

cppreference说:

In a function declaration, the keyword volatile may appear inside the square brackets that are used to declare an array type of a function parameter. It qualifies the pointer type to which the array type is transformed. The following two declarations declare the same function:

void f(double x[volatile], const double y[volatile]);

void f(double * volatile x, const double * volatile y);

此语法仅在 C 语言的函数参数中有效。

关于c - 出现在数组下标中的 "volatile"关键字的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47377106/

相关文章:

c - 避免在函数调用中从 volatile static uint8_t 转换为 uint8_t?

java - java中的volatile变量和内存屏障

c - 使用嵌入式C测试环境缺少头文件

c - 请解释这个结构的用法

python - 在 Python 中编译 C 代码的问题

php - 如何将数组值插入数据库表的列?

java - Volatile:为什么要阻止编译器重新排序代码

c - MSVC 和优化常量表达式

c++ - 如何使用 vector 中包含的 double[4][4] 数组?

PHP 和 MySQL : list of table entries in a second one