title: Initializing a nested struct with const members
body: <p>I have the following types, for illustration:</p>
  
  <pre><code>struct outer {
    struct inner {
      const int c;
      int x;
    } i;
    int y;
  };
  </code></pre>
  
  <p>I want to malloc <code>outer</code> and then, later, initialize <code>inner</code> to get the right const behavior for <code>outer.i.c</code>.</p>
  
  <p>For example, something like</p>
  
  <pre><code>struct outer *o = malloc(sizeof *o);
  o-&gt;y = find_y();
  int cc = find_c();
  int xx = find_x();
  o-&gt;i = { .c = cc, .x = xx };
  </code></pre>
  
  <p>but this gives me an error about <code>assignment of read-only member 'i'</code>, because it's an assignment, not an initialization.</p>
  
  <p>Is there a way to do something like this that's up-front to the compiler?  Let's consider tricks like casting away const with <code>*((int *) &amp;o-&gt;i.c)</code> or using memcpy on <code>&amp;o.i</code> as sneaking around the compiler.  I can get the bits where they need to be, but I am looking for the least sneaky way to do this.</p>
  
  <p>I am not using C++ (I'm using C99).</p>