In general there should never be a constant in the implementation files; other than 0, and sometimes 1, they should all be defined in the private header file.
In the case of int_stack
implementation, the constant 16 is used. However these represent two different constants - the size of the initial array and the value of the increment.
There are 2 different approaches to implementing the constants:
#define
.
#define INIT_INT_STACK 16
#define INCR_INT_STACK 16
enum
enum {
INIT_INT_STACK = 16,
INCR_INT_STACK = 16
};
My personal preference is the first approach.
Either way, replace the 16
in the implementation with the appropriate
constants.
void
verify_int_stack(
FILE * file,
int line,
const int_stack stack
)
{
verify( file, line, len_int_stack(stack) >= 0 );
verify( file, line, len_int_stack(stack) <= max_int_stack() );
verify( file, line, max_int_stack(stack) >= INIT_INT_STACK );
verify( file, line,
((max_int_stack(stack)-INIT_INT_STACK)%INCR_INT_STACK) == 0);
}
int_stack
make_int_stack(void)
{
int_stack stack = xalloc(struct int_stack);
x_max_int_stack(stack) = INIT_INT_STACK;
x_len_int_stack(stack) = 0;
x_vals_int_stack(stack) = xnalloc(int, INIT_INT_STACK);
VERIFY_INT_STACK(stack);
return stack;
}
void
push_int_stack(
int_stack stack,
int val
)
{
/* declarations and things... */
if( len == max ) {
nmax = max + INCR_INT_STACK;
/* ... */
}
/* ... */
}