title: How to not repeat myself in this situation? C functions that are the same but have different arguments
body: <p>Now I know what you are thinking - the thing that I described in the title sounds just like overloading. I know that is not a thing in C and I'm not going for it anyways. I have these 2 functions - ABSOLUTELY the same in their body, but the arguments are 2 different structs. Basically it's a binary search tree struct and a red black tree struct. As you may know the structs have only one difference - the red black tree struct contains one more field and that's the color one. Also the functions search, min, max, predecessor, successor.. those are going to have the EXACT same body but alas they take 2 different types of structs. And of course the insert and delete methods will be different.</p>
  
  <p>So I was thinking how can I avoid breaking the number one rule in programming and not repeat myself? I thought about a lot of solutions but none work when I try to find a way to implement it. I thought about just using one function for both but I can't do that since the structs are different. I thought about using macros but honestly I have no idea how to make those work and I am not even sure that they can avoid the problem that I have 2 different structs. I thought about making one generic struct and have the rb struct contain it and a color variable but this straight up changes the code with a few characters everywhere since I have to go one level deeper into the struct to get the values and I no longer have duplicate code.</p>
  
  <p>Just an example of what the problem looks like:</p>
  
  <pre><code>bst_search(bstTree t, char *k)
  {
      // Searching in tree
  }
  
  rb_search(rbTree t, char *k)
  {
      // SAME code for searching in tree
  }
  </code></pre>
  
  <p>If I was coding in java I would probably solve this using an abstract superclass but C doesn't have fancy stuff like that.</p>
  
  <p>Some extra info: both implementations have their own header and class files and I'd like to keep it that way. Right now I have duplicate code all over those 2 classes and the only things differing are the names of the functions and the structs (except for the insert and delete functions ofc).</p>
  
  <p>Sorry if this has an obvious solution I just don't find a way out of this without duplicating my code.</p>