\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[GSTACK\_\-DECL]{\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 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[GSTACK\_\-DEFN]{\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 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[GSTACK\_\-POP\_\-DEFN]{\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 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[GSTACK\_\-PUSH\_\-DEFN]{\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 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[GSTACK\_\-TOP\_\-DEFN]{\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 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[gstack\_\-pop]{\setlength{\rightskip}{0pt plus 5cm}void gstack\_\-pop (struct \hyperlink{structgstack}{gstack} $\ast$ {\em s}, \hyperlink{group__adt_g87ba7ca9dce36c22fe75a730a1d768a9}{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[gstack\_\-push]{\setlength{\rightskip}{0pt plus 5cm}int gstack\_\-push (struct \hyperlink{structgstack}{gstack} $\ast$ {\em s}, unsigned {\em datasize}, const void $\ast$ {\em data}, \hyperlink{group__adt_ga98f7f3499407a5dc1afdcbb20df2e15}{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[gstack\_\-top]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ gstack\_\-top (const struct \hyperlink{structgstack}{gstack} $\ast$ {\em s})}}
\label{group__adt__gstack_g89d5e3c467a1d97c60cb817ed5f4f3f6}


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