pgCC underscores

Hello,

I’m trying to compile a c++ code with pgCC under Fedora 3 Linux. It compiles ok using g++, so I believe it should be no problem for pgCC. I tried several compiler options following the user manual, but it fails all the time. The output looks like this:

$ /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 481: error: identifier "__offsetof__" is undefined
        comp_type.insertMember("a", HOFFSET(s1_t, a), PredType::NATIVE_INT);
                                    ^
1 error detected in the compilation of "tfile.cpp".

Any thoughts? Could it be just a path problem or is it related to the underscores?

Thanks,
Alex

Hi Alex,

offsetof” is a non-standard extension which we don’t support. Are you using it directly or are you using the offsetof macro?

If you are using the macro, try re-defining it to be:

#define 	offsetof(typ, fld)   ((int)(&(((typ*)0)->fld)))

I believe this is how GCC previously defined it.

Hope this helps,
Mat

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.

Hi Alex,

Like you, I’m not an expert in C++ so I’m not 100% sure if the warning is ok. I’d expect a warning about redfining a macro, it’s the “incompatible” part that concerns me. The macro I suggested and the one you used are both C macros so perhaps there’s something incompatable between the GNU C and GNU C++ definitions. I’ll ask our C++ expect and see what she thinks.

Actually the only reason I even know about “offsetof” is that I got hit with a similar problem. GCC 4.0 now defines “offsetof” to be “__builtin_offsetof”. In other words, they have put the macro definition of what offsetof is into the compiler itself. Eventually we’ll need add our own version of “__builtin_offsetof” but until then we’re stuck. Sorry for the rant…

  • Mat

Mat,

As for the “incompatible” issue, I thought it was simply meaning “different”, in the sense that the 2 definitions I posted are different and the compiler was complaining about that. Please do post the opinion of your c++ expert when you get her answer.

I know what you mean about gcc 4.0. People here are having lots of trouble with the porting of older codes to comply with the new structures in gcc 4.0, that’s exactly why I did not upgrade my system to Fedora Core 4: everything is (well, almost) working fine, no need to get new worries right now.

It’s always good to get some feedback, thanks.
Cheers,
Alex

Hi Alex,

From Deb:

Surprisingly, Mat’s simple C definition should work for you,
even though some C++ classes require runtime type identification.
Our C++ has been enhanced to support the C definition for offset.

You can ignore the warning message.

  • Mat

Dear Mat, Deb,

Thank you very much for all the help with this issue.

Cheers,
Alex