The checksum code introduces considerable run-time overhead. If it is not needed (say, after the corruption problem has been debugged), it should be turned off. This can be done using conditional compilation.
Conditional compilation usually involves #define
some variable to either 0 or 1. The code that is to be included/excluded is guarded by #if
of that variable. Thus, for instance:
void
pop_int_stack(
int_stack stack
)
{
VERIFY_INT_STACK(stack);
x_len_int_stack(stack)--;
#if( CHECKSUM_INT_STACK )
{
int len = len_int_stack(stack);
/* undo the old values in the checksum */
x_chksum_int_stack(stack) ^= (unsigned) len;
x_chksum_int_stack(stack) ^= (unsigned) vals_int_stack(len)[len-1];
/* update the checksum with new value */
x_chksum_int_stack(stack) ^= (unsigned) (len-1);
}
#endif
VERIFY_INT_STACK(stack);
}
The control variable CHECKSUM_INT_STACK
is defined in the private header file. It should be defined so that its value can be over-ridden during the compilation process.
/* in int_stack-private.h */
#ifndef CHECKSUM_INT_STACK
#define CHECKSUM_INT_STACK 0
#endif
In this case, by default, no checksum is computed. To turn it on compile using cc -DCHECKSUM_INT_STACK=1
.