This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

how to compute offset of data member at compile time (virtual class)


I need to compute the offset of a data member at compile time.
The class has virtual functions, and so the offsetof macro does
not work (why?). Is there a way to do this?

My example (compiler error on the printf line):

#include <stdio.h>
#include <stddef.h>

class Foo {
public:
  virtual void Bar();
  int m_x;
  char m_y;
  char z[30];
  float w;
};

int main(int argc, char **argv)
{
  printf("%d\n", offsetof(Foo, w));
}

Thanks,

j
-- 
John Gateley <gateley@jriver.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]