"read" : "write", array_access_exception_index, array_access_exception_base); return 1;

printf("Enter size of array a: "); scanf("%d", &asz); printf("Enter size of array b: "); scanf("%d", &bsz); printf("How many elements to copy: "); scanf("%d", &cnt);

alloc_array(&a, asz); alloc_array(&b, bsz); copy_array(&a, &b, cnt);

return 0;

Próba użycia: $ ./arrayexcept Enter size of array a: 15 Enter size of array b: 20 How many elements to copy: 11

$ ./arrayexcept Enter size of array a: 15 Enter size of array b: 20 How many elements to copy: 34 Trying to read at invalid offset 15 of array 0xbffff350

array_access_exception to adres aktualnego handlera wyjątku. array_access_exception_base i array_access_exception_index przechowują dodatkowe informacje zwracane przez wyjątek.

Wszystkie funkcje korzystające z tablic, takie jak copy_array, są o wiele prostsze niż funkcje, które sprawdzałaby jawnie granice tablicy.

Kategoria:Konstrukcje programistyczne