Hi Mat, thanks for the answer.
Actually this is not my code, I’m not really familiar with c++, I’m just trying to compile the code and use it. Your input gave me some good ideas, though, like searching for the definition used by gcc (ok, I should had think of that before, but I didn’t). This resulted in 2 different options:
- /lib/modules/
uname -r
/build/include/linux/stddef.h shows:
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
/usr/lib/gcc/i386-redhat-linux/3.4.4/include/stddef.h shows:
#define offsetof(TYPE, MEMBER) \
(__offsetof__ (reinterpret_cast <size_t> \
(&reinterpret_cast <const volatile char &> \
(static_cast<TYPE *> (0)->MEMBER))))
The first result seems pretty close to the definition you suggested, so I just added this to the problematic .cpp file:
#ifndef __offsetof__
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
As a result of that, the code compiled but with this warning:
$ /usr/pgi/linux86/6.0/bin/pgCC -I. -I../src -I./../src -I../../test -I../../src -I../../src -D_BSD_SOURCE -D_POSIX_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I/zlib/linux/zlib-1.2.1/lib -c tfile.cpp -o tfile.o
"tfile.cpp", line 38: warning: incompatible redefinition of macro "offsetof"
(declared at line 418 of
"/usr/lib/gcc/i386-redhat-linux/3.4.4/include/stddef.h")
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
^
I find this puzzling, since first the error message complained about offsetof not being defined! But anyway, by doing this I finally got the .o file. I tried also changing the definition on the .cpp file, just using the definition from /usr/lib/gcc/i386-redhat-linux/3.4.4/include/stddef.h, but then again I got the same error I stated with: " identifier offsetof is undefined ", so I went back to the first solution.
Now, my silly question is: how bad is that warning message? It is a silly question because obviously you couldn’t know about the full code I’m dealing with, so the implications are not that obvious. What I mean is, since I’m no expert in c++, I’m not sure if that replacement of definitions can be relevant or not. Can you shed some light on that?
Thanks again for your input. It’s really nice to have a forum like this to discuss these issues.
Alex.