Bug report

LN lutz.nitzsche@iga-gmbh.de
Thu Jun 12 16:35:00 GMT 2003


Dear GNUs...

I think that I have found a bug when compiling the macro 'offsetof'

for example

struct TYPE
{
    int MEMBER;
    int MEMBER2;
};

offsetof (TYPE,MEMBER) 
allways raises
 warning: invalid access to non-static data member 'TYPE::MEMBER' of NULL Object
 warning: perhaps the 'offsetof' macro was uses incorrectly

a workaround is to change the declaration in stddef.h changing the NULL-pointer to
a NOT NULL address:

#define offsetof(TYPE, MEMBER) (((size_t) &((TYPE *)8)->MEMBER)-8)

If you think that checking for NULL pointers is usefull and necessary at this point,
you should fix that workaround in stddef.h or implement the 'offsetof' macro as a real
C++ operator.


with best regards

Lutz Nitzsche



More information about the Gcc-bugs mailing list