Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

static keyword inside array [] brackets [duplicate]

I recently came across new use of static keyword. What does static mean here?

void fun(int some_array[static 7]);

EDIT : can someone give an example where this can be useful?

like image 537
Priyank Doshi Avatar asked Feb 18 '13 18:02

Priyank Doshi


1 Answers

The standard says in 6.7.6.3:

A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. If the keyword static also appears within the [ and ] of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression.

It's a feature introduced in C99. So there you have it: some_array must be at least 7 elements long.


As they say, there can't be a new standard without a new usage for the keyword static.

like image 105
cnicutar Avatar answered Oct 13 '22 04:10

cnicutar