invalid offsetof from non-POD type

Chris Croswhite
Fri Jan 10 04:02:00 GMT 2003

Hello all,

Perhaps someone could give me had with understanding this error:
"invalid offsetof from non-POD type; use pointer to member instead"

Here is the simplest test:

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

class Myclass {
          int _val;

struct foo_struct {
          Myclass a;
          void *bar;

int main(void)
          printf("offset is %d\n", offsetof(struct foo_struct, bar));

The class within the struct is causing offsetof a warning.  Could someone
describe why this is a warning and this produces invalid code.  If this is
correect, is there a way to turn off this warning?


More information about the Gcc-help mailing list