PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Displaying text in preprocessor

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



Joined: 27 Sep 2004
Posts: 4

PostPosted: Tue Jun 14, 2005 9:24 am    Post subject: Displaying text in preprocessor Reply with quote

I'd like to include a preprocessor statement which displays the user-defined compile time options selected; i.e. something like
#ifdef USE_LOWER
#echo "User has selected USE_LOWER flag
[some statements]
#else
#echo "User has NOT selected USE_LOWER flag"
#endif

Is there any way of doing this?

Phil
Back to top
View user's profile
mkcolg



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

PostPosted: Tue Jun 14, 2005 9:42 am    Post subject: Reply with quote

Hi Phil,

I don't believe there is any way to have the preprocessor do this. What are you trying to accomplish? Perhaps, there might be another method.

- Mat
Back to top
View user's profile
Phil Livermore



Joined: 27 Sep 2004
Posts: 4

PostPosted: Tue Jun 14, 2005 9:54 am    Post subject: Reply with quote

It's nothing fancy, but I'd be nice to remind the user what the flags selected actually do.
I simply want to display something about the code compilation at compile time.
Back to top
View user's profile
mkcolg



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

PostPosted: Wed Jun 15, 2005 9:38 am    Post subject: Reply with quote

Hi Phil,


While this doesn't do exactly what you want, you can try using the ident pragma to insert strings into your application's binary file and then use grep to determine what options were used.

Example:
Code:
% cat x.c
#include <stdio.h>

int main () {

#ifdef STR1
#pragma ident "HELLO_STR1"
#else
#pragma ident "HELLO_STR2"
#endif

  printf ("Hello\n");
}
% pgcc -DSTR1 x.c
% grep HELLO_STR1 a.out
Binary file a.out matches
% grep HELLO_STR2 a.out
% pgcc x.c
% grep HELLO_STR1 a.out
% grep HELLO_STR2 a.out
Binary file a.out matches


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



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

PostPosted: Wed Jun 15, 2005 11:25 am    Post subject: Reply with quote

I think your best solution would be to use the ident pragma with the strings command:
Code:
% cat x.c
#include <stdio.h>

#ifdef STR1
#pragma ident "HELLO INFO: STR1 WAS USED"
#else
#pragma ident "HELLO INFO: STR1 WAS NOT USED"
#endif

int main () {
  printf ("Hello\n");
}
% pgcc x.c -c
% strings -a x.o | grep "HELLO INFO"
HELLO INFO: STR1 WAS NOT USED


I should also note that this only works with C/C++.

- Mat
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