Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bizarre C statement [duplicate]

Tags:

c

c99

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,

like image 342
Akash Shende Avatar asked Jul 17 '13 18:07

Akash Shende


1 Answers

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
like image 150
ouah Avatar answered Oct 04 '22 06:10

ouah