title: Allocating memory with an undefined pointer
body: <p>I was surprised when <code>gcc -Wall</code> compiled this without warning. Is this really legitimate C? What are the risks of writing code like this?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct {
    int a;
    int b;
  } MyStruct;
  
  int main(void) {
    MyStruct *s = malloc(sizeof(*s)); // as opposed to malloc(sizeof(MyStruct))
    s-&gt;a = 5;
    printf("%d\n", s-&gt;a);
  }
  </code></pre>