

If you don't know how to create lists see \hyperlink{eina_list_01_example_page}{Adding elements to Eina\+\_\+\+List}. In this example we also use \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}
\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <\hyperlink{Eina_8h}{Eina.h}>}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   (void)argc;
   (void)argv;
   \hyperlink{struct__Eina__List}{Eina\_List} *list = NULL;
   \hyperlink{struct__Eina__List}{Eina\_List} *l;
   \textcolor{keywordtype}{void} *list\_data;

   \hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\_init}();

   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \hyperlink{group__Eina__Stringshare__Group_gac7a3f073cafb7af63b2c7cc2eabd1c1f}{eina\_stringshare\_add}(\textcolor{stringliteral}{"calvin"}));
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \hyperlink{group__Eina__Stringshare__Group_gac7a3f073cafb7af63b2c7cc2eabd1c1f}{eina\_stringshare\_add}(\textcolor{stringliteral}{"Leoben"}));
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \hyperlink{group__Eina__Stringshare__Group_gac7a3f073cafb7af63b2c7cc2eabd1c1f}{eina\_stringshare\_add}(\textcolor{stringliteral}{"D'Anna"}));
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \hyperlink{group__Eina__Stringshare__Group_gac7a3f073cafb7af63b2c7cc2eabd1c1f}{eina\_stringshare\_add}(\textcolor{stringliteral}{"Simon"}));
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \hyperlink{group__Eina__Stringshare__Group_gac7a3f073cafb7af63b2c7cc2eabd1c1f}{eina\_stringshare\_add}(\textcolor{stringliteral}{"Doral"}));
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \hyperlink{group__Eina__Stringshare__Group_gac7a3f073cafb7af63b2c7cc2eabd1c1f}{eina\_stringshare\_add}(\textcolor{stringliteral}{"Six"}));
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \hyperlink{group__Eina__Stringshare__Group_gac7a3f073cafb7af63b2c7cc2eabd1c1f}{eina\_stringshare\_add}(\textcolor{stringliteral}{"Sharon"}));

\end{DoxyCodeInclude}


This time we are going to iterate over our list in a different way\+: 
\begin{DoxyCodeInclude}

   \textcolor{keywordflow}{for}(l = list; l; l = \hyperlink{group__Eina__List__Group_gac264188a790dda0761d587578605bfd1}{eina\_list\_next}(l))
     printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, (\textcolor{keywordtype}{char}*)l->\hyperlink{struct__Eina__List_a043e22d601d3a0504f30255a43a25e7a}{data});

\end{DoxyCodeInclude}


And now we are going to iterate over the list backwards\+: 
\begin{DoxyCodeInclude}

   \textcolor{keywordflow}{for}(l = \hyperlink{group__Eina__List__Group_ga4c3a9eb5062f3b44c5dcef845cc7a72a}{eina\_list\_last}(list); l; l = \hyperlink{group__Eina__List__Group_gacd8294cbab7b4e053bcf754a92dd68e3}{eina\_list\_prev}(l))
      printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, (\textcolor{keywordtype}{char}*)\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}

   \hyperlink{group__Eina__List__Group_gae27a2c686a0a11693f9b06957c9bba83}{EINA\_LIST\_FREE}(list, list\_data)
     \hyperlink{group__Eina__Stringshare__Group_ga4453d2aff2b325c7b45048f30df9b1f5}{eina\_stringshare\_del}(list\_data);

\end{DoxyCodeInclude}
 \begin{DoxyNote}{Note}
We don't need to use \hyperlink{group__Eina__List__Group_ga608bd2fbf06293a1b794648990703ab4}{eina\+\_\+list\+\_\+free()} since \hyperlink{group__Eina__List__Group_gae27a2c686a0a11693f9b06957c9bba83}{E\+I\+N\+A\+\_\+\+L\+I\+S\+T\+\_\+\+F\+R\+E\+E} takes care of that.
\end{DoxyNote}
And shut everything down\+: 
\begin{DoxyCodeInclude}

   \hyperlink{group__Eina__Main__Group_ga6741fcaba116e31e96ce14dcfa03f568}{eina\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}


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