jmp_buf array_access_exception; struct array *array_access_exception_base; int array_access_exception_index;

struct array { int *data; int size;

void alloc_array(struct array *array, int size) { array->data = malloc(sizeof(int) * size); array->size = size;

int read_array(struct array *array, int offset) { if (offset < 0 || offset >= array->size)

array_access_exception_base = array; array_access_exception_index = offset; longjmp(array_access_exception, 1);

return array->data[offset];

void write_array(struct array *array, int offset, int value) { if (offset < 0 || offset >= array->size)

array_access_exception_base = array; array_access_exception_index = offset; longjmp(array_access_exception, 2);

array->data[offset] = value;

void copy_array(struct array *a, struct array *b, int cnt) { int i; for(i=0; i<cnt; ++i) write_array(b, i, read_array(a, i));

int main() { struct array a,b; int asz, bsz, cnt; int xretval;

if((xretval = setjmp(array_access_exception)) != 0)

fprintf(stderr, "Trying to %s at invalid offset %i of array %p\n", (xretval == 1) ?