title: Casting a struct in a constant initializer in LLVM
body: <p>Consider the following types:</p>
  
  <pre><code>%foo = type {%bar}
  %bar = type {i32, i32}
  %baz = type {i8, i8}
  </code></pre>
  
  <p><code>%foo</code> is supposed to be similar to a C union and be able hold both a <code>%bar</code> and a <code>%baz</code>, which is normally no problem, as a <code>%bar</code> is much bigger than a <code>%baz</code>.</p>
  
  <p>Writing a <code>%baz</code> to a <code>%foo</code> in memory would probably work by getting a pointer into the field of <code>%foo</code> and casting the pointer to <code>%baz*</code>.</p>
  
  <p>Now consider I have the following constant:</p>
  
  <pre><code>@c = constant %foo ...
  </code></pre>
  
  <p>How do I initialize it with a <code>%baz</code> inside? Doing it like this gives a type error:</p>
  
  <pre><code>@c = constant %foo { %bar {i8 0, i8 0} }
  </code></pre>
  
  <p>In C I would just cast it, but LLVM doesn't seem to have a cast instruction, that can cast a whole struct.</p>
  
  <p>How can I initialize the constant with a <code>%baz</code>?</p>