title: 'Multipurpose' linked list implementation in pure C
body: <p>This is not exactly a technical question, since I know C kind of enough to do the things I need to (I mean, in terms of not 'letting the language get in your way'), so this question is basically a 'what direction to take' question.</p>
  
  <p>Situation is: I am currently taking an advanced algorithms course, and for the sake of 'growing up as programmers', I am required to use pure C to implement the practical assignments (it works well: pretty much any small mistake you make actually forces you to understand completely what you're doing in order to fix it). In the course of implementing, I obviously run into the problem of having to implement the 'basic' data structures from the ground up: actually not only linked lists, but also stacks, trees, et cetera.</p>
  
  <p>I am focusing on lists in this topic because it's typically a structure I end up using a lot in the program, either as a 'main' structure or as a 'helper' structure for other bigger ones (for example, a hash tree that resolves conflicts by using a linked list).</p>
  
  <p><strong>This requires that the list stores elements of lots of different types.</strong> I am assuming here as a premise that I don't want to re-code the list for every type. So, I can come up with these alternatives:</p>
  
  <ul>
  <li>Making a list of void pointers (kinda inelegant; harder to debug)</li>
  <li>Making only one list, but having a <strong>union</strong> as 'element type', containing all element types I will use in the program (easier to debug; wastes space if elements are not all the same size)</li>
  <li>Using a preprocessor macro to regenerate the code for every type, in the style of <a href="http://sglib.sourceforge.net" rel="noreferrer">SGLIB</a>, 'imitating' C++'s STL (creative solution; doesn't waste space; elements have the explicit type they actually are when they are returned; <em>any change in list code can be really dramatic</em>)</li>
  <li>Your idea/solution</li>
  </ul>
  
  <p><strong>To make the question clear: which one of the above is best?</strong></p>
  
  <p>PS: Since I am basically in an academic context, I am also very interested in the view of people working with pure C out there in the industry. I understand that most pure C programmers are in the embedded devices area, where I don't think this kind of problem I am facing is common. However, if anyone out there knows how it's done 'in the real world', I would be very interested in your opinion.</p>