title: sign extension in C
body: <p>I'm looking here to understand sign extension:
  <a href="http://www.shrubbery.net/solaris9ab/SUNWdev/SOL64TRANS/p8.html" rel="nofollow">http://www.shrubbery.net/solaris9ab/SUNWdev/SOL64TRANS/p8.html</a></p>
  
  <pre class="lang-c prettyprint-override"><code>    struct foo {
          unsigned int    base:19, rehash:13;  
      };
  
      main(int argc, char *argv[]) 
      {
          struct foo  a;
          unsigned long addr;
  
          a.base = 0x40000;
          addr = a.base &lt;&lt; 13;        /* Sign extension here! */
          printf("addr 0x%lx\n", addr);
  
          addr = (unsigned int)(a.base &lt;&lt; 13);  /* No sign extension here! */
          printf("addr 0x%lx\n", addr);
      }
  </code></pre>
  
  <p>They claim this:</p>
  
  <p>------------------ 64 bit:</p>
  
  <pre><code>% cc -o test64 -xarch=v9 test.c
  % ./test64
  addr 0xffffffff80000000
  addr 0x80000000
  %
  </code></pre>
  
  <p>------------------ 32 bit:</p>
  
  <pre><code>% cc -o test32 test.c
  % ./test32
  addr 0x80000000
  addr 0x80000000
  %
  </code></pre>
  
  <p>I have 3 questions:</p>
  
  <ol>
  <li>What is sign extension ? Yes I read wiki, but didn't understand when type promotion occurs, what's going on with sign extension?</li>
  <li>Why ffff.. in 64 bit(referring addr) ?</li>
  <li>When I do type cast, why no sign extension?</li>
  </ol>
  
  <p>EDIT:
  4. Why not an issue in 32 bit system?</p>