This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
how to compute offset of data member at compile time (virtual class)
- From: John Gateley <gateley at jriver dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 25 Oct 2007 11:19:48 -0500
- Subject: 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>