PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

pgCC underscores
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
acorreia



Joined: 19 Apr 2005
Posts: 14

PostPosted: Thu Nov 10, 2005 6:45 am    Post subject: pgCC underscores Reply with quote

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:

Code:

$ /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
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6205
Location: The Portland Group Inc.

PostPosted: Thu Nov 10, 2005 3:32 pm    Post subject: Reply with quote

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:
Code:

#define    offsetof(typ, fld)   ((int)(&(((typ*)0)->fld)))
I believe this is how GCC previously defined it.

Hope this helps,
Mat
Back to top
View user's profile
acorreia



Joined: 19 Apr 2005
Posts: 14

PostPosted: Fri Nov 11, 2005 6:46 am    Post subject: Reply with quote

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:
    Code:

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

    /usr/lib/gcc/i386-redhat-linux/3.4.4/include/stddef.h shows:
    Code:

    #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:
Code:

#ifndef __offsetof__
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif

As a result of that, the code compiled but with this warning:
Code:

$ /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.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6205
Location: The Portland Group Inc.

PostPosted: Fri Nov 11, 2005 5:55 pm    Post subject: Reply with quote

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
Back to top
View user's profile
acorreia



Joined: 19 Apr 2005
Posts: 14

PostPosted: Fri Nov 11, 2005 6:57 pm    Post subject: Reply with quote

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
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group