int main(int argc, char **argv) { int stack_capacity; if(argc < 2) { die("Stack capacity hasn't been specified as parameter."); } else { stack_capacity = atoi(*(argv + 1)); } if (stack_capacity < 1) die("Stack size is too small."); struct Stack *st = Stack_create(stack_capacity); int push_value; int pop_value; push_value = 100; if(Stack_push(st, push_value)){ printf("Stack overflow.\n"); } else { printf("%d has been successfully pushed.\n", push_value); }; push_value = 10; if(Stack_push(st, push_value)){ printf("Stack overflow.\n"); } else { printf("%d has been successfully pushed.\n", push_value); }; push_value = 1; if(Stack_push(st, push_value)){ printf("Stack overflow.\n"); } else { printf("%d has been successfully pushed.\n", push_value); }; if(Stack_pop(st, &pop_value)) { printf("Stack is empty.\n"); } else { printf("%d has been successfully popped.\n", pop_value); }; if(Stack_pop(st, &pop_value)) { printf("Stack is empty.\n"); } else { printf("%d has been successfully popped.\n", pop_value); }; if(Stack_pop(st, &pop_value)) { printf("Stack is empty.\n"); } else { printf("%d has been successfully popped.\n", pop_value); }; Stack_destruct(st); return 0; }
void CPU_destruct(CPU_t* cpu) { assert(cpu); Stack_destruct(cpu->stack_cpu); free(cpu->stack_cpu); free(cpu->code); cpu = NULL; }