While I was browsing cppreference, I saw a strange type array in function parameters like this:
void f(double x[volatile], const double y[volatile]);
So, What is the purpose of the volatile
keyword appearing inside an array subscript? What does it do?
The volatile
keyword is used to declare an array type of a function parameter.
Here, double x[volatile]
is equivalent to double * volatile x
.
The cppreference says :
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);
This syntax only valid in C language in function parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With