This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Bug report


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]