Stack library
In this section, we are going to write a small library that is going to be loaded and used by programs written in other programming languages. The library is about a Stack class that offers some basic operations like push or pop on stack objects. Stack objects are created and destroyed by the library itself and there is a constructor function, as well as a destructor function, to fulfill this purpose.
Next, you can find the library's public interface, which exists as part of the cstack.h
header file:
#ifndef _CSTACK_H_ #define _CSTACK_H_ #include <unistd.h> #ifdef __cplusplus extern "C" { #endif #define TRUE 1 #define FALSE 0 typedef int bool_t; typedef struct { char* data; size_t len; } value_t; typedef struct cstack_type cstack_t; typedef void (*deleter_t)(value_t* value); value_t make_value(char* data, size_t len); value_t copy_value(char* data, size_t len); void free_value(value_t* value); cstack_t* cstack_new(); void...