title: offsetof at compile time
body: <p>Is there a way of finding the offset of a member of a structure at compile-time? I wish to create a constant containing the offset of a structure member. In the following code the <code>offsetof()</code> macro works in the first <code>printf</code> statement. However, the use in line 10 to declare <code>ofs</code> generates the error:</p>
  
  <blockquote>
    <p>"Cannot resolve '->' operator as a constant expression". </p>
  </blockquote>
  
  <p>Is there any other way of doing it?</p>
  
  <pre><code>struct MyStruct
  {
     unsigned long lw;
     unsigned char c[5];
     int i;
     int j;
     unsigned long last;
  };
  
  const int ofs = offsetof(struct MyStruct, i);  // This line in error
  
  int main(void)
  {
     printf("Offset of c = %d.\n", offsetof(struct MyStruct, c) );
     printf("Offset of i = %d.\n", ofs );
     return 0;
  }
  </code></pre>