title: How do I fit a variable sized char array in a struct?
body: <p>I don't understand how the reallocation of memory for a struct allows me to insert a larger char array into my struct.</p>
  
  <p>Struct definition:</p>
  
  <pre><code>typedef struct props
  {
      char northTexture[1];
      char southTexture[1];
      char eastTexture[1];
      char westTexture[1];
      char floorTexture[1];
      char ceilingTexture[1];
  } PROPDATA;
  </code></pre>
  
  <p>example:</p>
  
  <pre><code>void function SetNorthTexture( PROPDATA* propData, char* northTexture )
  {
      if( strlen( northTexture ) != strlen( propData-&gt;northTexture ) )
      {
          PROPDATA* propPtr = (PROPDATA*)realloc( propData, sizeof( PROPDATA ) +
              sizeof( northTexture ) );
          if( propPtr != NULL )
          {
              strcpy( propData-&gt;northTexture, northTexture );
          } 
      }
      else
      {
          strcpy( propData-&gt;northTexture, northTexture );
      }
  }
  </code></pre>
  
  <p>I have tested something similar to this and it appears to work, I just don't understand how it does work. Now I expect some people are thinking "just use a char*" but I can't for whatever reason. The string has to be stored in the struct itself.</p>
  
  <p>My confusion comes from the fact that I haven't resized my struct for any specific purpose. I haven't somehow indicated that I want the extra space to be allocated to the north texture char array in that example. I imagine the extra bit of memory I allocated is used for actually storing the string, and somehow when I call strcpy, it realises there is not enough space...</p>
  
  <p>Any explanations on how this works (or how this is flawed even) would be great.</p>