5313 shaares
127 private links
127 private links
The people who created C sure loved keeping the number of keywords low, and today I’m going to show you yet another place you can use the static
keyword in C99.
You might have seen function parameter declaration for array parameters that include the size:
void foo(int myArray[10]);
The function will still receive a naked int *
, but the [10]
part can serve as documentation for the people reading the code, saying that the function expects an array of 10 ints.
But, you can actually also use the keyword static
between the brackets:
void bar(int myArray[static 10]);
This tells the compiler that it should assume that the array passed to bar has at least 10 elements. (Note that this rules out a NULL
pointer!)