\hypertarget{group__adt__gstack}{
\section{adt gstack: Generic simple stack.}
\label{group__adt__gstack}\index{adt gstack: Generic simple stack.@{adt gstack: Generic simple stack.}}
}
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{structgstack__node}{gstack\_\-node}
\item 
struct \hyperlink{structgstack}{gstack}
\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define \hyperlink{group__adt__gstack_g4f8f96eebb71e97682246e416882860a}{GSTACK\_\-DECL}(PREFIX, TYPE)
\item 
\#define \hyperlink{group__adt__gstack_g1a6b766c1e85ad942288d34b3b452a51}{GSTACK\_\-PUSH\_\-DEFN}(PREFIX, TYPE, COPY)
\item 
\#define \hyperlink{group__adt__gstack_g9fa46018a9c712216d216afe6cc43fea}{GSTACK\_\-TOP\_\-DEFN}(PREFIX, TYPE)
\item 
\#define \hyperlink{group__adt__gstack_gb5b75f18ad1625de1b08b456290554a3}{GSTACK\_\-POP\_\-DEFN}(PREFIX, FREE)
\item 
\#define \hyperlink{group__adt__gstack_g6db6fa756dd91724aab0a0d9513389cb}{GSTACK\_\-DEFN}(PREFIX, TYPE, COPY, FREE)
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
int \hyperlink{group__adt__gstack_gf83a5565c8a02ed6a2a95aacebfdd448}{gstack\_\-push} (struct \hyperlink{structgstack}{gstack} $\ast$d, unsigned datasize, const void $\ast$data, \hyperlink{group__adt_ga98f7f3499407a5dc1afdcbb20df2e15}{adt\_\-copy\_\-fn} $\ast$fn)
\item 
void $\ast$ \hyperlink{group__adt__gstack_g89d5e3c467a1d97c60cb817ed5f4f3f6}{gstack\_\-top} (const struct \hyperlink{structgstack}{gstack} $\ast$s)
\item 
void \hyperlink{group__adt__gstack_g1e4ffbe6a4c391351d7543ae47f9c2bf}{gstack\_\-pop} (struct \hyperlink{structgstack}{gstack} $\ast$s, \hyperlink{group__adt_g87ba7ca9dce36c22fe75a730a1d768a9}{adt\_\-free\_\-fn} $\ast$fn)
\end{CompactItemize}


\subsection{Detailed Description}
A generic stack is a first-in-last-out structure defined here based on three primary operations: push, top, and pop. Pushing an element onto a stack adds it to the head of the list. The top operation fetches the most recently pushed element still on the stack, and popping removes it. 

\subsection{Define Documentation}
\hypertarget{group__adt__gstack_g4f8f96eebb71e97682246e416882860a}{
\index{adt\_\-gstack@{adt\_\-gstack}!GSTACK\_\-DECL@{GSTACK\_\-DECL}}
\index{GSTACK\_\-DECL@{GSTACK\_\-DECL}!adt_gstack@{adt\_\-gstack}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GSTACK\_\-DECL(PREFIX, TYPE)}}
\label{group__adt__gstack_g4f8f96eebb71e97682246e416882860a}


\textbf{Value:}

\begin{Code}\begin{verbatim}extern int PREFIX##_push(struct gstack* s, TYPE const* data); \
extern TYPE* PREFIX##_top(struct gstack* s); \
extern void PREFIX##_pop(struct gstack* s);
\end{verbatim}
\end{Code}
Declare specialized {\tt \hyperlink{structgstack}{gstack}} functions. \begin{Desc}
\item[Examples: ]\par
\hyperlink{adt_2gstack__test_8c-example}{adt/gstack\_\-test.c}.\end{Desc}
\hypertarget{group__adt__gstack_g6db6fa756dd91724aab0a0d9513389cb}{
\index{adt\_\-gstack@{adt\_\-gstack}!GSTACK\_\-DEFN@{GSTACK\_\-DEFN}}
\index{GSTACK\_\-DEFN@{GSTACK\_\-DEFN}!adt_gstack@{adt\_\-gstack}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GSTACK\_\-DEFN(PREFIX, TYPE, COPY, FREE)}}
\label{group__adt__gstack_g6db6fa756dd91724aab0a0d9513389cb}


\textbf{Value:}

\begin{Code}\begin{verbatim}GSTACK_PUSH_DEFN(PREFIX,TYPE,COPY) \
GSTACK_TOP_DEFN(PREFIX,TYPE) \
GSTACK_POP_DEFN(PREFIX,FREE)
\end{verbatim}
\end{Code}
Define all the specialized {\tt \hyperlink{structgstack}{gstack}} functions. If {\tt COPY} is {\tt NULL}, a simple memcpy is used instead. If {\tt FREE} is {\tt NULL}, no attempt is made to free the data. \begin{Desc}
\item[Examples: ]\par
\hyperlink{adt_2gstack__test_8c-example}{adt/gstack\_\-test.c}.\end{Desc}
\hypertarget{group__adt__gstack_gb5b75f18ad1625de1b08b456290554a3}{
\index{adt\_\-gstack@{adt\_\-gstack}!GSTACK\_\-POP\_\-DEFN@{GSTACK\_\-POP\_\-DEFN}}
\index{GSTACK\_\-POP\_\-DEFN@{GSTACK\_\-POP\_\-DEFN}!adt_gstack@{adt\_\-gstack}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GSTACK\_\-POP\_\-DEFN(PREFIX, FREE)}}
\label{group__adt__gstack_gb5b75f18ad1625de1b08b456290554a3}


\textbf{Value:}

\begin{Code}\begin{verbatim}void PREFIX##_pop(struct gstack* s) { \
  gstack_pop(s, (adt_free_fn*)(FREE)); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structgstack}{gstack}} pop function. \hypertarget{group__adt__gstack_g1a6b766c1e85ad942288d34b3b452a51}{
\index{adt\_\-gstack@{adt\_\-gstack}!GSTACK\_\-PUSH\_\-DEFN@{GSTACK\_\-PUSH\_\-DEFN}}
\index{GSTACK\_\-PUSH\_\-DEFN@{GSTACK\_\-PUSH\_\-DEFN}!adt_gstack@{adt\_\-gstack}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GSTACK\_\-PUSH\_\-DEFN(PREFIX, TYPE, COPY)}}
\label{group__adt__gstack_g1a6b766c1e85ad942288d34b3b452a51}


\textbf{Value:}

\begin{Code}\begin{verbatim}int PREFIX##_push(struct gstack* s, TYPE const* data) { \
  return gstack_push(s, sizeof *data, data, (adt_copy_fn*)COPY); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structgstack}{gstack}} push function. \hypertarget{group__adt__gstack_g9fa46018a9c712216d216afe6cc43fea}{
\index{adt\_\-gstack@{adt\_\-gstack}!GSTACK\_\-TOP\_\-DEFN@{GSTACK\_\-TOP\_\-DEFN}}
\index{GSTACK\_\-TOP\_\-DEFN@{GSTACK\_\-TOP\_\-DEFN}!adt_gstack@{adt\_\-gstack}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GSTACK\_\-TOP\_\-DEFN(PREFIX, TYPE)}}
\label{group__adt__gstack_g9fa46018a9c712216d216afe6cc43fea}


\textbf{Value:}

\begin{Code}\begin{verbatim}TYPE* PREFIX##_top(struct gstack* s) { \
  return (s->head == 0) ? 0 : (TYPE*)s->head->data; \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structgstack}{gstack}} top function. 

\subsection{Function Documentation}
\hypertarget{group__adt__gstack_g1e4ffbe6a4c391351d7543ae47f9c2bf}{
\index{adt\_\-gstack@{adt\_\-gstack}!gstack\_\-pop@{gstack\_\-pop}}
\index{gstack\_\-pop@{gstack\_\-pop}!adt_gstack@{adt\_\-gstack}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void gstack\_\-pop (struct {\bf gstack} $\ast$ {\em s}, {\bf adt\_\-free\_\-fn} $\ast$ {\em fn})}}
\label{group__adt__gstack_g1e4ffbe6a4c391351d7543ae47f9c2bf}


Remove the first (most recently pushed) element from the queue. If the free function {\tt fn} is {\tt NULL} no data freeing is done. Note that this does not return a pointer to the popped item, as once the item has been popped it is also freed. \hypertarget{group__adt__gstack_gf83a5565c8a02ed6a2a95aacebfdd448}{
\index{adt\_\-gstack@{adt\_\-gstack}!gstack\_\-push@{gstack\_\-push}}
\index{gstack\_\-push@{gstack\_\-push}!adt_gstack@{adt\_\-gstack}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int gstack\_\-push (struct {\bf gstack} $\ast$ {\em s}, unsigned {\em datasize}, const void $\ast$ {\em data}, {\bf adt\_\-copy\_\-fn} $\ast$ {\em fn})}}
\label{group__adt__gstack_gf83a5565c8a02ed6a2a95aacebfdd448}


Add a new element onto the stack. If the copy function {\tt fn} is {\tt NULL} memcpy is used in its place. \hypertarget{group__adt__gstack_g89d5e3c467a1d97c60cb817ed5f4f3f6}{
\index{adt\_\-gstack@{adt\_\-gstack}!gstack\_\-top@{gstack\_\-top}}
\index{gstack\_\-top@{gstack\_\-top}!adt_gstack@{adt\_\-gstack}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ gstack\_\-top (const struct {\bf gstack} $\ast$ {\em s})}}
\label{group__adt__gstack_g89d5e3c467a1d97c60cb817ed5f4f3f6}


Return the address of first (most recently pushed) element in the queue. 