title: How to access a member of a union without naming it?
body: <p>I have some code that is very similar to the following</p>
  
  <pre><code>struct T {
      union {
          unsigned int x;
          struct {
              unsigned short xhigh;
              unsigned short xlow;
          };
      } x;
      /* ...repeated a handful of times for different variables in T... */
  };
  </code></pre>
  
  <p>This does exactly what you'd expect: It allows me to declare a variable of type <code>struct T</code> and access either <code>t.x.x</code> or <code>t.x.xhigh</code> or <code>t.x.xlow</code>. So far so good.</p>
  
  <p>However, <strong>I would really like it if I could do just <code>t.x</code></strong> in the common case of wanting to access the value of the union as an <code>unsigned int</code> quantity, but retain the ability to access the high- and low-order portions independently without resorting to bit masking and shifting, and without invoking undefined behavior.</p>
  
  <p><strong>Is that possible in C?</strong></p>
  
  <p><strong>If it is possible, then what is the C syntax for the declaration?</strong></p>
  
  <p>When I try the naiive approach of simply accessing <code>t.x</code> instead of <code>t.x.x</code>, I get warning messages like (this particular one is from a <code>printf()</code> call):</p>
  
  <pre><code>cc -ansi -o test -Wall test.c
  test.c: In function ‘my_function’:
  test.c:13:2: warning: format ‘%X’ expects argument of type ‘unsigned int’, but argument 2 has type ‘const union &lt;anonymous&gt;’ [-Wformat]
  </code></pre>
  
  <p>Using <code>-std=c11</code> instead of <code>-ansi</code> yields the same warning.</p>