7
void test(int x[static 10]);  

int main()  
{  
    int a[]={1,2,3,4,5,6,7,8,9,10,11};  
    test(a);  
    return 0;  
}  

void test(int x[static 10])  
{  
    printf("%d",x[9]);  
} 

I was looking for bizarre C statements. I found this one, But could not understand what is the use of static 10 in that statement. Is it same as int x[10]?

Another thing, you can use volatile also, in place of static e.g int x[volatile 10]
Anybody knows what is the use of this kinda declaration?

PS: Compiled using GCC 4.6.3,

Casey
  • 41,449
  • 7
  • 95
  • 125
Akash Shende
  • 599
  • 4
  • 15

1 Answers1

5

It's a hint for the compiler telling that the x pointer parameter points to the first element of an array of at least 10 elements.

For example:

test(NULL);  // undefined behavior
ouah
  • 142,963
  • 15
  • 272
  • 331