Wednesday, 21 August 2013

static size of array in C99

static size of array in C99

A very simple program in C:
#include <stdio.h>
#include <stdlib.h>
void process(int array[static 5]){
int i;
for(i=0; i<5; i++)
printf("%d ", array[i]);
printf("\n");
}
int main(){
process((int[]){1,2,3});
process(NULL);
return 0;
}
I compile it: gcc -std=c99 -Wall -o demo demo.c
It does compile and when I run it, it crashes (quite predictable).
Why? What is the purpose of the static keyword in array parameter (whats
the name of this construct btw?) ?

No comments:

Post a Comment