/** * dstack.c - Implementations of simple stack functions. * Based closely on code taken from section 4.3 of K&R, although * I've removed the precondition checking since error messages * should be passed to the client, rather than to the user. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include // For fprintf #include "dstack.h" // +-----------+------------------------------------------------------ // | Constants | // +-----------+ /** * The maximum size of the stack. */ #define MAXSIZE 8 // +---------+-------------------------------------------------------- // | Globals | // +---------+ /** * The array in which we store values. */ double dstack[MAXSIZE]; /** * The position in the array that stores the most-recently pushed * value. (When 0, there is nothing on the stack. */ int sp = 0; // +--------------------+--------------------------------------------- // | Exported Functions | // +--------------------+ void dpush (double d) { dstack[sp++] = d; } // dpush double dpop (void) { return dstack[--sp]; } // dpop