Space/Science — HabitableZone

Space/Science » in reply to Intermittent problems are tough to fix

It's like the "array out of bounds" bug in C programming

The error that keeps C programmers up at night is the "array out of bounds" bug, e.g.

double foo[13] ;
foo[14] = 1.23 ;
printf("%f\n", foo[14]) ;

Sometimes the above code works extactly right on the first pop. More often than not, it bites you on the ass, 6 months in the future when the boss is asking for a demo in front of some customers. At that point standard diagnostics won't work to find it, e.g. gdb. More often than not, the divide-and-conqure debug method won't work either (the error point just moves around).

Young programmers take note! Use this approach in C programming:

#define N_limit 13
register int i ;
int foo[N_limit] ;
for (i = 0; i < N_limit; i++) {
foo[i] = i ;
}

The same symbol that defines the array's size also limits the "for" loop. This approach stops most of the "array out of bounds" bugs before they clamp onto your behind.

Gary

Log in or register to post.

The whole thread (45 posts)