- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
#include <stdio.h>
void print_first_three(int a[static 3]) {
for (int i = 0; i < 3; i++) {
printf("%i ", a[i]);
}
printf("\n");
}
int main() {
int nums[] = {1, 2, 3, 4, 5};
print_first_three(nums);
return 0;
}
int a[static 3], господа. Минусуем те, кто знал о таком.
In function parameter lists, additional syntax elements are allowed within the array declarators: the keyword static and qualifiers, which may appear in any order before the size expression (they may also appear even when the size expression is omitted).
In each function call to a function where a parameter of array type uses the keyword static between [ and ], the value of the actual parameter must be a valid pointer to the first element of an array with at least as many elements as specified by expression.
--http://en.cppreference.com/w/c/language/array
как и [volatile *]
но эти языки все равно намного лучше говно-языков, которые и знать не хочется. но приходится. пример: Visual Basic.
только тем, кому нельзя в С++ и у кого не вижуалстудия, будут сидеть изучать новые сишкограни
static вроде уже в C99 есть.
А Паскаль за его bounds checking по умолчанию сишники недолюбливают.
Тупой компилятор может проверить только то, что внутри функции не нарушается контракт о доступе не более, чем к трём элементам. А размер передаваемого массива не проверяет.