PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

_Pragma(string) --- broken implementation?

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
dima2011



Joined: 11 May 2011
Posts: 8

PostPosted: Sun Sep 15, 2013 11:50 pm    Post subject: _Pragma(string) --- broken implementation? Reply with quote

Hi, I need to define a portable _Pragma("omp ...").
This could have be done by
#define STRINGIFy(n) #n
#define STRINGIFY(n) STRINGIFy(n)
#define PRAGMA_OMP(args) _Pragma(STRINGIFY(omp args))
and it works with many compilers, but not with pgcc 13.6.
pgcc complaints on use of the PRAGMA_OMP(parallel) thus:

PGC-S-0269-_Pragma requires one argument which must be a string (x.c: 10)

If instead of preprocessor stringification I use _Pragma("omp parallel") in that place, everything works fine.

When I try to see if PRAGMA_OMP is expanded wrong, pgcc -E just complaints with the above error and eats up the expansion of the macro definition.

When I replace _Pragma with X_Pragma I can see that cpp expansion goes correctly.

I therefore conclude that _Pragma is processed before its argument string is formed by the preprocessor.

Could you advise what to do with this issue?
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Sep 16, 2013 1:08 pm    Post subject: Reply with quote

Hi dima2011,

Per the C99 standard, section 6.10.9, the _Pragma operator only accepts a string literal or via macro expansion with the following form:

Quote:
#define PRAGMA_OMP(args) PRAGMA(omp args)
#define PRAGMA(x) _Pragma(#x)

PRAGMA_OMP(foo)


- Mat
Back to top
View user's profile
dima2011



Joined: 11 May 2011
Posts: 8

PostPosted: Mon Sep 16, 2013 7:27 pm    Post subject: Reply with quote

Hi Mat,

Thank you very much for the solution and for the reference to the section in C99 standard. This means, with respect to _Pragma operator the PGI compiler is the most standard conforming compiler of those few I know.

Regards
Dima
Back to top
View user's profile
mkcolg



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

PostPosted: Tue Sep 17, 2013 9:46 am    Post subject: Reply with quote

Hi Dima,

_Pragma is problematic since it's poorly defined in the standard, hence, there's wide variation in it's implementation. We certainly can try to accommodate you, though it seems to me that your version is more complex than what's shown in the standard. Do you wish me to add a feature request?

- Mat
Back to top
View user's profile
dima2011



Joined: 11 May 2011
Posts: 8

PostPosted: Tue Sep 17, 2013 11:40 pm    Post subject: Reply with quote

Hi Mat,

I don't see a need in feature request, since the solution you have given works just fine in all my cases. And I do not see cases where forming a string for _Pragma would be a problem. So, no need in FR.

Thanks
Dima
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
Page 1 of 1

 
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