

If you don\textquotesingle{}t know how to create lists see \mbox{\hyperlink{eina_list_01_example_page}{Adding elements to Eina\+\_\+\+List}}. In this example we also use \mbox{\hyperlink{group__Eina__Stringshare__Group}{Stringshare}}, however it should be possible to understand the code regardless of previous knowledge about it.

Here we have the usual list creation code with a twist, now we are using as data for the list memory that has to be freed later on. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   (void)argc;}
\DoxyCodeLine{   (void)argv;}
\DoxyCodeLine{   \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *list = NULL;}
\DoxyCodeLine{   \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *l;}
\DoxyCodeLine{   \textcolor{keywordtype}{void} *list\_data;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Main__Group_gafee4bfc0e509b6ffed6598edf6f4b3de}{eina\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   list = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(list, \mbox{\hyperlink{group__Eina__Stringshare__Group_ga5293082680141132ffcacc28866ef0ef}{eina\_stringshare\_add}}(\textcolor{stringliteral}{"calvin"}));}
\DoxyCodeLine{   list = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(list, \mbox{\hyperlink{group__Eina__Stringshare__Group_ga5293082680141132ffcacc28866ef0ef}{eina\_stringshare\_add}}(\textcolor{stringliteral}{"Leoben"}));}
\DoxyCodeLine{   list = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(list, \mbox{\hyperlink{group__Eina__Stringshare__Group_ga5293082680141132ffcacc28866ef0ef}{eina\_stringshare\_add}}(\textcolor{stringliteral}{"D'Anna"}));}
\DoxyCodeLine{   list = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(list, \mbox{\hyperlink{group__Eina__Stringshare__Group_ga5293082680141132ffcacc28866ef0ef}{eina\_stringshare\_add}}(\textcolor{stringliteral}{"Simon"}));}
\DoxyCodeLine{   list = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(list, \mbox{\hyperlink{group__Eina__Stringshare__Group_ga5293082680141132ffcacc28866ef0ef}{eina\_stringshare\_add}}(\textcolor{stringliteral}{"Doral"}));}
\DoxyCodeLine{   list = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(list, \mbox{\hyperlink{group__Eina__Stringshare__Group_ga5293082680141132ffcacc28866ef0ef}{eina\_stringshare\_add}}(\textcolor{stringliteral}{"Six"}));}
\DoxyCodeLine{   list = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(list, \mbox{\hyperlink{group__Eina__Stringshare__Group_ga5293082680141132ffcacc28866ef0ef}{eina\_stringshare\_add}}(\textcolor{stringliteral}{"Sharon"}));}

\end{DoxyCodeInclude}


This time we are going to iterate over our list in a different way\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{for}(l = list; l; l = \mbox{\hyperlink{group__Eina__List__Group_gac264188a790dda0761d587578605bfd1}{eina\_list\_next}}(l))}
\DoxyCodeLine{     printf(\textcolor{stringliteral}{"\%s\(\backslash\)n"}, (\textcolor{keywordtype}{char}*)l-\/>\mbox{\hyperlink{struct__Eina__List_a043e22d601d3a0504f30255a43a25e7a}{data}});}

\end{DoxyCodeInclude}


And now we are going to iterate over the list backwards\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{for}(l = \mbox{\hyperlink{group__Eina__List__Group_ga4c3a9eb5062f3b44c5dcef845cc7a72a}{eina\_list\_last}}(list); l; l = \mbox{\hyperlink{group__Eina__List__Group_gacd8294cbab7b4e053bcf754a92dd68e3}{eina\_list\_prev}}(l))}
\DoxyCodeLine{      printf(\textcolor{stringliteral}{"\%s\(\backslash\)n"}, (\textcolor{keywordtype}{char}*)\mbox{\hyperlink{group__Eina__List__Group_gaec845f0bfb16a14e8d7f0cd508ca7e9c}{eina\_list\_data\_get}}(l));}

\end{DoxyCodeInclude}


And now we need to free up the memory allocated during creation of the list\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__List__Group_gae27a2c686a0a11693f9b06957c9bba83}{EINA\_LIST\_FREE}}(list, list\_data)}
\DoxyCodeLine{     \mbox{\hyperlink{group__Eina__Stringshare__Group_ga495411b0bc85b9c0d59ec7255a025260}{eina\_stringshare\_del}}(list\_data);}

\end{DoxyCodeInclude}
 \begin{DoxyNote}{Note}
We don\textquotesingle{}t need to use \mbox{\hyperlink{group__Eina__List__Group_ga608bd2fbf06293a1b794648990703ab4}{eina\+\_\+list\+\_\+free()}} since \mbox{\hyperlink{group__Eina__List__Group_gae27a2c686a0a11693f9b06957c9bba83}{E\+I\+N\+A\+\_\+\+L\+I\+S\+T\+\_\+\+F\+R\+EE}} takes care of that.
\end{DoxyNote}
And shut everything down\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Main__Group_ga2c8b4020427108a30c44707af22c99d3}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


The full source code can be found on the examples folder on the \mbox{\hyperlink{eina_list_04_c}{eina\+\_\+list\+\_\+04.c}} file. 