title: Union as an argument to a function in C
body: <p>I am wondering if it is possible to use unions as arguments to a function:</p>
  
  <p>Let's say I have two structures:</p>
  
  <pre><code>struct complex_attribute{
      struct generic_attribute *sub_attributes[20];
  };
  
  struct generic_attribute{
      int current_value;
  };
  </code></pre>
  
  <p>And a union of these two:</p>
  
  <pre><code>union union_attribute{
      struct complex_attribute *complex;
      struct generic_attribute *generic;
  };
  </code></pre>
  
  <p>I want to create a function that takes in either a complex_attribute or a generic_attribute:</p>
  
  <pre><code>struct tagged_attribute* prepare_tagged_attribute(int code, union union_attribute *attribute)
  </code></pre>
  
  <p>However, when I make a call to this function </p>
  
  <pre><code>prepare_tagged_attribute(2, pointer_to_complex_structure);
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code> passing argument 2 of ‘prepare_tagged_attribute’ from incompatible pointer type
  </code></pre>
  
  <p>So I take it that pointer to a a complex structure is not necessarily a pointer of type union (which makes sense)... but then is it possible to use unions in this way?</p>