Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the "volatile" keyword appearing inside an array subscript?

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?

like image 525
msc Avatar asked Nov 19 '17 12:11

msc


1 Answers

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.

like image 140
msc Avatar answered Sep 30 '22 15:09

msc