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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux