title: How can I do a structure type conversion like this?
body: <p>say if I have two structure types:</p>
  
  <pre><code>typedef struct
  {
     unsigned int * a;
     char * b;
     char * c;
  }TYPEA;
  
  typedef struct
  {
     unsigned int * a;
     unsigned int * b;
  }TYPEB;
  </code></pre>
  
  <p>And I also have a pointer array, which contains pointer pointing to <code>TYPEA</code> types:</p>
  
  <pre><code>TYPEA* AArray[1] =
  {
     &amp;ga,
  };
  </code></pre>
  
  <p><code>ga</code> is defined as:</p>
  
  <pre><code>TYPEA ga =
  {
     &amp;num1,
     &amp;b,
     &amp;c,
  };
  </code></pre>
  
  <p>If I have another <code>TYPEA</code> var defined, I can modify <code>AArray[0]</code>'s content's value, like this:</p>
  
  <pre><code>TYPEA another_ga =
  {
     &amp;num3,
     &amp;b,
     &amp;c,
  };
  
  void change_AArray()
  {
     *AArray[0] = another_ga;
  }
  </code></pre>
  
  <p>This works perfectly good, but the question is, as <code>TYPEA</code> and <code>TYPEB</code>'s first 32bits are same(Both are <code>unsigned int</code>) is it possible for me to change <code>AArray</code>'s <code>ga</code>'s content to a <code>TYPEB</code> structure?</p>
  
  <p>Here are my attempts:</p>
  
  <pre><code>void change_AArray()
  {
     /* *AArray[0] = another_ga; */
  
     /* Compile Error */
     /* *AArray[0] = gb; */
  
     /* Compile Error */
     /* *AArray[0] = (TYPEA)gb; */
  
     /* Passed compile, but AArray[0] is not changed */
     /* AArray[0] = (TYPEA*)&amp;gb; */
  }
  </code></pre>
  
  <p>I then tried to add another pointer and put it in <code>AArray[0]</code> instead of using <code>&amp;ga</code>, but it can't pass compile stage, I think C is requiring a constant in the initialize list.</p>
  
  <pre><code>TYPEA * pga = &amp;ga;
  TYPEA* AArray[1] =
  {
     pga, // error, needs a constant expression.
  };
  void change_AArray()
  {
     AArray[0] = (TYPEA*)&amp;gb;
  }
  </code></pre>
  
  <p>Is it possible to do the type conversion?</p>
  
  <p>The entire code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  typedef struct
  {
     unsigned int * a;
     char * b;
     char * c;
  }TYPEA;
  
  typedef struct
  {
     unsigned int * a;
     unsigned int * b;
  }TYPEB;
  
  int num1 = 10, num2 = 20, num3 = 30;
  char b = 'b', c = 'c';
  
  TYPEA ga =
  {
     &amp;num1,
     &amp;b,
     &amp;c,
  };
  
  TYPEA another_ga =
  {
     &amp;num3,
     &amp;b,
     &amp;c,
  };
  
  TYPEB gb =
  {
     &amp;num2,
     &amp;num3,
  };
  
  TYPEA* AArray[1] =
  {
     &amp;ga,
  };
  
  void change_AArray()
  {
     *AArray[0] = another_ga;
     /* How can I do this conversion? */
     /* *AArray[0] = gb; */
  }
  
  int main(int argc, const char *argv[])
  {
     printf("ga.a: %d\n", *ga.a);
     printf("gb.b: %d\n", *gb.a);
  
     change_AArray();
  
     printf("After calling change_AArray()\n");
     printf("ga.a: %d\n", *ga.a);
     printf("gb.b: %d\n", *gb.a);
  
     return 0;
  }
  </code></pre>