This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: warning: invalid offsetof from non-POD type
- From: John Quigley <johnw at lowestplane dot org>
- To: Eljay Love-Jensen <eljay at adobe dot com>,gcc-help at gcc dot gnu dot org
- Date: Sat, 29 Mar 2003 10:59:29 -0800
- Subject: Re: warning: invalid offsetof from non-POD type
- References: <4.3.2.7.2.20030328115130.00b29680@iplan-mn.corp.adobe.com>
On Friday 28 March 2003 9:52 am, Eljay Love-Jensen wrote:
> Hi John,
>
> Could you send a compilable code snippet that generates the error.
>
> Thanks,
> --Eljay
Here you go. Note that it is a warning, not an error.
// BEGIN CODE
#include <cstddef>
#include <iostream>
using namespace std;
class Foo
{
public:
int x;
char fillerdata[256];
int y;
Foo()
{
x = 0;
y = 0;
}
};
int main()
{
int yoffset = offsetof(Foo, y); // triggers warning
cout << "yoffset: " << yoffset << endl;
Foo foo;
// get a pointer to y using the computed offset
int* yptr = (int*)(((unsigned char*)&foo) + yoffset);
// test it by assigning value
*yptr = 15;
cout << "foo values: " << foo.x << ", " << foo.y << endl;
return 0;
}
// END CODE